suve

awful: function: dt-str

Declaration

string :dt-str ( string $FORMAT , float $DT )
string :dt-str ( string $FORMAT )
string :dt-str ( float $DT )
string :dt-str

Summary

Returns a string representation of the provided DateTime value, formatted according to the format string.
If $FORMAT is omitted, defaults to Y-M-D H:I.
If $DT is omitted, defaults to now value. (:dt-now).

Format string

Character Description Example
:!: Day
d Day of month, 1 or 2 digits 1, 20
D Day of month, 2 digits with leading zeros 01, 15
a Day of week, three letters Mon, Wed
A Day of week, full name Monday, Wednesday
w Day of week, single digit - 1 for Monday, 7 for Sunday.
Available since rev.38.
3, 7
:!: Month
m Month of year, 1 or 2 digits 3, 11
M Month of year, 2 digits with leading zeros 05, 12
o Month name, three letters Feb, Jul
O Month name, full January, September
:!: Year
y Year, two digits 14, 89
Y Year, four digits 1995, 2020
:!: Hour
h Hour of day, 1 or 2 digits. 24h clock by default. 5, 18
H Hour of day, 2 digits with leading zeros. 24h clock by default. 04, 16
p a or p depending on am/pm. Affects hH formatting by changing the clock to 12h. a, p
P am or pm depending on am/pm. Affects hH formatting by changing the clock to 12h. am, pm
:!: Minutes
i Minutes, 1 or 2 digits 8, 38
I Minutes, 2 digits with leading zeros 07, 49
:!: Seconds
s Seconds, 1 or 2 digits 4, 14
S Seconds, 2 digits with leading zeros 02, 22
:!: ms
z Milliseconds, 1, 2 or 3 digits 9, 74
Z Milliseconds, 3 digits with leading zeros 007, 091
:!: Timestamp
U Unix timestamp.
Available since rev.38.
1397562139
Any other (non-formatting) characters are left as-is.

Example

# :dt-str example
:set &dt :dt-encode i1995 i11 i15 i4 i6 i8
:writeln :dt-str s"a D O Y, H:I:S" $dt   # Custom format and DateTime
:writeln :dt-str s"a D O Y, H:I:S"       # Custom format, now DT
:writeln :dt-str $dt                     # Default format, custom DT
:writeln :dt-str                         # Default format, now DT

wikipage modified on 2014/0601/2317