Time: Difference between revisions
Jump to navigation
Jump to search
Add javascript snippet |
|||
Line 5: | Line 5: | ||
Time returns the current system time. | Time returns the current system time. | ||
== Example == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 13: | Line 13: | ||
RightNow = Time | RightNow = Time | ||
Print "The time now is " & RightNow | Print "The time now is " & RightNow | ||
</pre> | |||
== Example (JavaScript) == | |||
<pre> | |||
// Time Example | |||
/* Time returns current system time */ | |||
time = function(tm) { | |||
if (!tm || tm=='unassigned' || tm=='') { | |||
dtm = new Date(); | |||
tm = dtm.toString(); | |||
} else { | |||
dtm = new Date("1/1 "+tm); //needs to be date time format | |||
} | |||
var ampm = (tm.toUpperCase().indexOf('AM') > -1) ? ' AM' : ' PM'; | |||
hr = dtm.getHours(); | |||
if (hr < 12) { | |||
ampm = ' AM'; | |||
} else if (hr > 12) { | |||
ampm = ' PM'; | |||
hr -= 12; | |||
if (hr==12) ampm = ' AM'; //midnight | |||
} | |||
mn = '0'+dtm.getMinutes(); | |||
mn0 = mn.substr(mn.length-2,2); | |||
ss = '0'+dtm.getSeconds(); | |||
ss0 = ss.substr(ss.length-2,2); | |||
return hr+':'+mn0+':'+ss0+ampm; | |||
} | |||
var RightNow; | |||
RightNow = time(); | |||
NSB.Print("The time now is " + RightNow); | |||
</pre> | </pre> | ||
Revision as of 19:07, 19 May 2013
Time
Description
Time returns the current system time.
Example (Basic)
Rem Time Example 'Time returns current system time Dim RightNow RightNow = Time Print "The time now is " & RightNow
Example (JavaScript)
// Time Example /* Time returns current system time */ time = function(tm) { if (!tm || tm=='unassigned' || tm=='') { dtm = new Date(); tm = dtm.toString(); } else { dtm = new Date("1/1 "+tm); //needs to be date time format } var ampm = (tm.toUpperCase().indexOf('AM') > -1) ? ' AM' : ' PM'; hr = dtm.getHours(); if (hr < 12) { ampm = ' AM'; } else if (hr > 12) { ampm = ' PM'; hr -= 12; if (hr==12) ampm = ' AM'; //midnight } mn = '0'+dtm.getMinutes(); mn0 = mn.substr(mn.length-2,2); ss = '0'+dtm.getSeconds(); ss0 = ss.substr(ss.length-2,2); return hr+':'+mn0+':'+ss0+ampm; } var RightNow; RightNow = time(); NSB.Print("The time now is " + RightNow);
Output
The time now is 10:52:44 PM (sample time output is system dependant)
Related Items
Date, Day, DateAdd, Hour, Minute, Month, Now, Second, WeekDay, Year (and many more)