TimeValue: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
JwellsNB (talk | contribs)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
''This function is for BASIC compatibility. It is not available in pure JavaScript projects.''
TimeValue(''time'')
TimeValue(''time'')


Line 19: Line 21:
Print "Half past five:", FiveThirty
Print "Half past five:", FiveThirty
Print "Noon:", Noon
Print "Noon:", Noon
</pre>
== Example (JavaScript) ==
<pre>
// TimeValue Example
/* TimeValue returns a time */
TimeValue = function(tm) {
  var 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 FiveThirty, Noon;
FiveThirty = TimeValue("5:30 PM");
Noon = TimeValue("12:00");
NSB.Print("Half past five: " + FiveThirty);
NSB.Print("Noon: " + Noon);
</pre>
</pre>


Line 67: Line 38:


[[Category:Date and Time]]
[[Category:Date and Time]]
[[Category:BASIC Functions]]

Latest revision as of 15:37, 25 March 2019

This function is for BASIC compatibility. It is not available in pure JavaScript projects.

TimeValue(time)

Description

TimeValue returns a time from, time, which is usually a string, but any expression that can represent a time ranging from 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 PM), can be used.

If time is a string that consists of numbers separated by time separators, it recognizes hour, minute, and second in the order specified by the system short time format, using zero for unspecified components. TimeValue recognizes time in both 12-hour and 24-hour format.

Time separators are characters that separate hour, minute and second when a time is formatted as a string, they are determined by your system settings.

Example (Basic)

Rem TimeValue Example
'TimeValue returns a time
Dim FiveThirty, Noon
FiveThirty = TimeValue("5:30 PM")
Noon = TimeValue("12:00")
Print "Half past five:", FiveThirty
Print "Noon:", Noon

Output

Half past five:      05:30:00 PM
Noon:  12:00:00 PM
(sample time output is system dependant)

Related Items

DateValue