TimeSerial: Difference between revisions
Jump to navigation
Jump to search
m Ghenne moved page Timeserial to TimeSerial |
Add javascript snippet |
||
Line 5: | Line 5: | ||
TimeSerial returns a time constructed from the given hour, minute, and second. The required parameter, ''hour'', is any numeric expression ranging from 0 to 23. The required parameters, ''minute'' and ''second'', can be any numeric expression. | TimeSerial returns a time constructed from the given hour, minute, and second. The required parameter, ''hour'', is any numeric expression ranging from 0 to 23. The required parameters, ''minute'' and ''second'', can be any numeric expression. | ||
== Example == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 15: | Line 15: | ||
Print "Half past five:", FiveThirty | Print "Half past five:", FiveThirty | ||
Print "Noon:", Noon | Print "Noon:", Noon | ||
</pre> | |||
== Example (JavaScript) == | |||
<pre> | |||
// TimeSerial Example | |||
/* TimeSerial builds a time from its parts */ | |||
TimeSerial = function(hr,mn,ss) { | |||
var dtm = new Date("1/1 "+hr+':'+mn+':'+ss); //needs to be date time format | |||
var ampm = ' 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 FiveThirty, Noon; | |||
FiveThirty = TimeSerial(11 - 6, 30, 0); | |||
Noon = TimeSerial(12, 0, 0); | |||
NSB.Print("Half past five: " + FiveThirty); | |||
NSB.Print("Noon: " + Noon); | |||
</pre> | </pre> | ||
Revision as of 06:26, 19 May 2013
TimeSerial(hour, minute, second)
Description
TimeSerial returns a time constructed from the given hour, minute, and second. The required parameter, hour, is any numeric expression ranging from 0 to 23. The required parameters, minute and second, can be any numeric expression.
Example (Basic)
Rem TimeSerial Example 'TimeSerial builds a time from its parts Dim FiveThirty, Noon FiveThirty = TimeSerial(11 - 6, 30, 0) Noon = TimeSerial(12, 0, 0) Print "Half past five:", FiveThirty Print "Noon:", Noon
Example (JavaScript)
// TimeSerial Example /* TimeSerial builds a time from its parts */ TimeSerial = function(hr,mn,ss) { var dtm = new Date("1/1 "+hr+':'+mn+':'+ss); //needs to be date time format var ampm = ' 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 FiveThirty, Noon; FiveThirty = TimeSerial(11 - 6, 30, 0); Noon = TimeSerial(12, 0, 0); NSB.Print("Half past five: " + FiveThirty); NSB.Print("Noon: " + Noon);
Output
Half past five: 05:30:00 AM Noon: 12:00:00 PM (sample time output is system dependant)