Definition: |
include builtins\timedate.e
string s = format_timedate(timedate td, string fmt=default_format) |
Description: | Convert a timedate into a string. |
Comments: |
The td parameter is normally a result originally from
parse_date_string(), and possibly adjusted.
You can also pass the result of
date() to this routine, as long as fmt does not contain a timezone, or
set_timezone() has been applied to the output of date().
The fmt parameter is a single format string, defaulted via set_timedate_formats(). If no fmt parameter is provided and the routine latter has not been invoked, the initial default of "h:mpm Dddd Mmmm ddth, yyyy" leads to a result such as "5:37pm Sunday October 23rd, 2016". It is perfectly acceptable to create and post-process several fragments before stitching them all together for the final result. The only exception is that any am/pm indicator must always be in the same fragment as the hour. You may also, performance considerations aside, feel that include builtins\timedate.e if format_timedate(td,"Dddd")="Monday" then is clearer or otherwise makes debugging easier than the equivalent enum SUN=1,MON,TUE,WED,THU,FRI,SAT -- (no standard constants yet exist for these) if td[DT_DOW]=MON then |
Example: |
include builtins\timedate.e ?format_timedate(date(),"'It is' h:mmpm") -- output is eg "It is 12:47pm" ?format_timedate(date(),"'On' Dddd, Mmmm dth, YYYY") -- output is eg "On Wednesday, July 20th, 2016" |
See Also: | timedate, the timedate type, parse_date_string, date, format strings, set_timedate_formats |