Skip to content

Commit 9e9a6a4

Browse files
explain in more detail and add examples
1 parent 0572bef commit 9e9a6a4

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

lib/elixir/lib/calendar.ex

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -496,38 +496,55 @@ defmodule Calendar do
496496
497497
The accepted formats for `string_format` are:
498498
499-
Format | Description | Examples (in ISO)
500-
:----- | :-------------------------------------------------------------------------------------------------------- | :------------------------
501-
a | Abbreviated name of day | Mon
502-
A | Full name of day | Monday
503-
b | Abbreviated month name | Jan
504-
B | Full month name | January
505-
c | Preferred date+time representation | 2018-10-17 12:34:56
506-
d | Day of the month | 01, 31
507-
f | Microseconds (truncated to the microsecond precision, but *does not support width and padding modifiers*) | 000000, 999999, 0123
508-
H | Hour using a 24-hour clock | 00, 23
509-
I | Hour using a 12-hour clock | 01, 12
510-
j | Day of the year | 001, 366
511-
m | Month | 01, 12
512-
M | Minute | 00, 59
513-
p | "AM" or "PM" (noon is "PM", midnight as "AM") | AM, PM
514-
P | "am" or "pm" (noon is "pm", midnight as "am") | am, pm
515-
q | Quarter | 1, 2, 3, 4
516-
s | Number of seconds since the Epoch, 1970-01-01 00:00:00+0000 (UTC) | 1565888877
517-
S | Second | 00, 59, 60
518-
u | Day of the week | 1 (Monday), 7 (Sunday)
519-
x | Preferred date (without time) representation | 2018-10-17
520-
X | Preferred time (without date) representation | 12:34:56
521-
y | Year as 2-digits | 01, 01, 86, 18
522-
Y | Year | -0001, 0001, 1986
523-
z | +hhmm/-hhmm time zone offset from UTC (empty string if naive) | +0300, -0530
524-
Z | Time zone abbreviation (empty string if naive) | CET, BRST
525-
% | Literal "%" character | %
499+
Format | Description | Examples (in ISO)
500+
:----- | :----------------------------------------------------------------------- | :------------------------
501+
a | Abbreviated name of day | Mon
502+
A | Full name of day | Monday
503+
b | Abbreviated month name | Jan
504+
B | Full month name | January
505+
c | Preferred date+time representation | 2018-10-17 12:34:56
506+
d | Day of the month | 01, 31
507+
f | Microseconds (uses its precision for width and padding) | 000000, 999999, 0123
508+
H | Hour using a 24-hour clock | 00, 23
509+
I | Hour using a 12-hour clock | 01, 12
510+
j | Day of the year | 001, 366
511+
m | Month | 01, 12
512+
M | Minute | 00, 59
513+
p | "AM" or "PM" (noon is "PM", midnight as "AM") | AM, PM
514+
P | "am" or "pm" (noon is "pm", midnight as "am") | am, pm
515+
q | Quarter | 1, 2, 3, 4
516+
s | Number of seconds since the Epoch, 1970-01-01 00:00:00+0000 (UTC) | 1565888877
517+
S | Second | 00, 59, 60
518+
u | Day of the week | 1 (Monday), 7 (Sunday)
519+
x | Preferred date (without time) representation | 2018-10-17
520+
X | Preferred time (without date) representation | 12:34:56
521+
y | Year as 2-digits | 01, 01, 86, 18
522+
Y | Year | -0001, 0001, 1986
523+
z | +hhmm/-hhmm time zone offset from UTC (empty string if naive) | +0300, -0530
524+
Z | Time zone abbreviation (empty string if naive) | CET, BRST
525+
% | Literal "%" character | %
526526
527527
Any other character will be interpreted as an invalid format and raise an error.
528528
529+
### `%f` Microseconds
530+
531+
`%f` does not support width and padding modifiers. It will be formatted by truncating
532+
the microseconds to the precision of the `microseconds` field of the struct, with a
533+
minimum precision of 1.
534+
529535
## Examples
530536
537+
Microsecond formatting:
538+
539+
iex> Calendar.strftime(~U[2019-08-26 13:52:06Z], "%y-%m-%d %H:%M:%S.%f")
540+
"19-08-26 13:52:06.0"
541+
542+
iex> Calendar.strftime(~U[2019-08-26 13:52:06.048Z], "%y-%m-%d %H:%M:%S.%f")
543+
"19-08-26 13:52:06.048"
544+
545+
iex> Calendar.strftime(~U[2019-08-26 13:52:06.048531Z], "%y-%m-%d %H:%M:%S.%f")
546+
"19-08-26 13:52:06.048531"
547+
531548
Without user options:
532549
533550
iex> Calendar.strftime(~U[2019-08-26 13:52:06.0Z], "%y-%m-%d %I:%M:%S %p")

0 commit comments

Comments
 (0)