Usage
Syntax: formattimestring(str format, int time)
Returns a string with the formatted time.
Explanation
formattimestring takes the given input time (relative to timevar2) and formats it against the given input format. The input format takes input like the strftime function in some other languages.
The markers in the format are substituted with the correct time values and the entire formatted time is returned. All markers are one letter with a preceding percent sign (i.e. %H). Anything that is given in the input format that does not follow this format is treated as a literal and ignored. Literals will, however, be returned in the result. For instance, %H:%M will return a value like 00:00 including the literal : character.
Some of the supported conversion markers are listed as follows:
Marker | Description |
---|---|
%a | Abbreviated weekday name (like Mon) |
%A | Full weekday name (like Monday) |
%b | Abbreviated month name (like Jan) |
%B | Full month name (like January) |
%C | Century number represented as two digit number |
%d | Day of the month represented as a number (from 01 to 31) |
%H | Hour represented as a decimal number using a 24-hour clock (from 0 to 23) |
%I | Hour represented as a decimal number using a 12-hour clock (from 1 to 12) |
%j | Day of the year represented as a number |
%m | Month of the year represented as a number |
%M | Minute of the hour represented as a number |
%p | Either AM or PM (midnight is AM and midday is PM) |
%S | Seconds of the minute represented as a number |
%u | Day of the week represented as a number (from 1 to 7 where Monday is 1) |
%U | Week of the year represented as a number (from 1 to 53) |
%w | Day of the week represented as a number (from 0 to 6 where Monday is 0) |
%y | Year represented as a number without the century (from 00 to 99) |
%Y | Year represented as a number including the century |
%z | Timezone as offset from GMT |
The full list is available in the Linux Manual (man strftime).
Example
You can use formattimestring as follows:
function onCreated() { echo(formattimestring("%d/%M/%Y %H:%M", 1276989159)); }
… which would echo "19/12/2010 23:12" (bearing in mind that 1276989159 was the value of timevar2 at the given time).
function onCreated() { echo(formattimestring("%d/%M/%Y %H:%M", timevar2)); }
… would output the current date and time in the same format as the above example.
Categories
CategoryFunctionServerside
CategoryExpansionRequired
There is one comment on this page. [Display comment]