formatTime -package:time
Substitute various time-related information for each %-code in the
string, as per
formatCharacter.
The general form is
%<modifier><width><alternate><specifier>,
where
<modifier>,
<width>, and
<alternate> are optional.
<modifier>
glibc-style modifiers can be used before the specifier (here marked as
z):
- %-z no padding
- %_z pad with spaces
- %0z pad with zeros
- %^z convert to upper case
- %#z convert to lower case (consistently, unlike
glibc)
<width>
Width digits can also be used after any modifiers and before the
specifier (here marked as
z), for example:
- %4z pad to 4 characters (with default padding
character)
- %_12z pad with spaces to 12 characters
<alternate>
An optional
E character indicates an alternate formatting.
Currently this only affects
%Z and
%z.
<specifier>
For all types (note these three are done by
formatTime, not by
formatCharacter):
TimeZone
For
TimeZone (and
ZonedTime and
UTCTime):
- %z timezone offset in the format
±HHMM
- %Ez timezone offset in the format
±HH:MM
- %Z timezone name (or else offset in the format
±HHMM)
- %EZ timezone name (or else offset in the format
±HH:MM)
LocalTime
For
LocalTime (and
ZonedTime and
UTCTime
and
UniversalTime):
- %c as dateTimeFmt locale (e.g.
%a %b %e %H:%M:%S %Z %Y)
TimeOfDay
For
TimeOfDay (and
LocalTime and
ZonedTime
and
UTCTime and
UniversalTime):
- %R same as %H:%M
- %T same as %H:%M:%S
- %X as timeFmt locale (e.g.
%H:%M:%S)
- %r as time12Fmt locale (e.g.
%I:%M:%S %p)
- %P day-half of day from (amPm
locale), converted to lowercase, am,
pm
- %p day-half of day from (amPm
locale), AM, PM
- %H hour of day (24-hour), 0-padded to two chars,
00 - 23
- %k hour of day (24-hour), space-padded to two
chars, 0 - 23
- %I hour of day-half (12-hour), 0-padded to two
chars, 01 - 12
- %l hour of day-half (12-hour), space-padded to two
chars, 1 - 12
- %M minute of hour, 0-padded to two chars,
00 - 59
- %S second of minute (without decimal part),
0-padded to two chars, 00 - 60
- %q picosecond of second, 0-padded to twelve chars,
000000000000 - 999999999999.
- %Q decimal point and fraction of second, up to 12
second decimals, without trailing zeros. For a whole number of
seconds, %Q omits the decimal point unless padding is
specified.
UTCTime and ZonedTime
For
UTCTime and
ZonedTime:
- %s number of whole seconds since the Unix epoch.
For times before the Unix epoch, this is a negative number. Note that
in %s.%q and %s%Q the decimals are positive, not
negative. For example, 0.9 seconds before the Unix epoch is formatted
as -1.1 with %s%Q.
DayOfWeek
For
DayOfWeek (and
Day and
LocalTime and
ZonedTime and
UTCTime and
UniversalTime):
- %u day of week number for Week Date format,
1 (= Monday) - 7 (= Sunday)
- %w day of week number, 0 (= Sunday) -
6 (= Saturday)
- %a day of week, short form (snd from
wDays locale), Sun - Sat
- %A day of week, long form (fst from
wDays locale), Sunday -
Saturday
Day
For
Day (and
LocalTime and
ZonedTime and
UTCTime and
UniversalTime):
- %D same as %m/%d/%y
- %F same as %Y-%m-%d
- %x as dateFmt locale (e.g.
%m/%d/%y)
- %Y year, no padding. Note %0Y and
%_Y pad to four chars
- %y year of century, 0-padded to two chars,
00 - 99
- %C century, no padding. Note %0C and
%_C pad to two chars
- %B month name, long form (fst from
months locale), January -
December
- %b, %h month name, short form (snd
from months locale), Jan - Dec
- %m month of year, 0-padded to two chars,
01 - 12
- %d day of month, 0-padded to two chars,
01 - 31
- %e day of month, space-padded to two chars,
1 - 31
- %j day of year, 0-padded to three chars,
001 - 366
- %f century for Week Date format, no padding. Note
%0f and %_f pad to two chars
- %V week of year for Week Date format, 0-padded to
two chars, 01 - 53
- %U week of year where weeks start on Sunday (as
sundayStartWeek), 0-padded to two chars, 00 -
53
- %W week of year where weeks start on Monday (as
mondayStartWeek), 0-padded to two chars, 00 -
53
Duration types
The specifiers for
DiffTime,
NominalDiffTime,
CalendarDiffDays, and
CalendarDiffTime are
semantically separate from the other types. Specifiers on negative
time differences will generally be negative (think
rem rather
than
mod).
NominalDiffTime and DiffTime
Note that a "minute" of
DiffTime is simply 60 SI seconds,
rather than a minute of civil time. Use
NominalDiffTime to
work with civil time, ignoring any leap seconds.
For
NominalDiffTime and
DiffTime:
- %w total whole weeks
- %d total whole days
- %D whole days of week
- %h total whole hours
- %H whole hours of day
- %m total whole minutes
- %M whole minutes of hour
- %s total whole seconds
- %Es total seconds, with decimal point and up to
<width> (default 12) decimal places, without trailing zeros. For
a whole number of seconds, %Es omits the decimal point unless
padding is specified.
- %0Es total seconds, with decimal point and
<width> (default 12) decimal places.
- %S whole seconds of minute
- %ES seconds of minute, with decimal point and up
to <width> (default 12) decimal places, without trailing zeros.
For a whole number of seconds, %ES omits the decimal point
unless padding is specified.
- %0ES seconds of minute as two digits, with decimal
point and <width> (default 12) decimal places.
CalendarDiffDays
For
CalendarDiffDays (and
CalendarDiffTime):
- %y total years
- %b total months
- %B months of year
- %w total weeks, not including months
- %d total days, not including months
- %D days of week
CalendarDiffTime
For
CalendarDiffTime:
- %h total hours, not including months
- %H hours of day
- %m total minutes, not including months
- %M minutes of hour
- %s total whole seconds, not including months
- %Es total seconds, not including months, with
decimal point and up to <width> (default 12) decimal places,
without trailing zeros. For a whole number of seconds, %Es
omits the decimal point unless padding is specified.
- %0Es total seconds, not including months, with
decimal point and <width> (default 12) decimal places.
- %S whole seconds of minute
- %ES seconds of minute, with decimal point and up
to <width> (default 12) decimal places, without trailing zeros.
For a whole number of seconds, %ES omits the decimal point
unless padding is specified.
- %0ES seconds of minute as two digits, with decimal
point and <width> (default 12) decimal places.
Substitute various time-related information for each %-code in the
string, as per
formatCharacter.
The general form is
%<modifier><width><alternate><specifier>,
where
<modifier>,
<width>, and
<alternate> are optional.
<modifier>
glibc-style modifiers can be used before the specifier (here marked as
z):
- %-z no padding
- %_z pad with spaces
- %0z pad with zeros
- %^z convert to upper case
- %#z convert to lower case (consistently, unlike
glibc)
<width>
Width digits can also be used after any modifiers and before the
specifier (here marked as
z), for example:
- %4z pad to 4 characters (with default padding
character)
- %_12z pad with spaces to 12 characters
<alternate>
An optional
E character indicates an alternate formatting.
Currently this only affects
%Z and
%z.
<specifier>
For all types (note these three are done by
formatTime, not by
formatCharacter):
TimeZone
For
TimeZone (and
ZonedTime and
UTCTime):
- %z timezone offset in the format
±HHMM
- %Ez timezone offset in the format
±HH:MM
- %Z timezone name (or else offset in the format
±HHMM)
- %EZ timezone name (or else offset in the format
±HH:MM)
LocalTime
For
LocalTime (and
ZonedTime and
UTCTime
and
UniversalTime):
- %c as dateTimeFmt locale (e.g.
%a %b %e %H:%M:%S %Z %Y)
TimeOfDay
For
TimeOfDay (and
LocalTime and
ZonedTime
and
UTCTime and
UniversalTime):
- %R same as %H:%M
- %T same as %H:%M:%S
- %X as timeFmt locale (e.g.
%H:%M:%S)
- %r as time12Fmt locale (e.g.
%I:%M:%S %p)
- %P day-half of day from (amPm
locale), converted to lowercase, am,
pm
- %p day-half of day from (amPm
locale), AM, PM
- %H hour of day (24-hour), 0-padded to two chars,
00 - 23
- %k hour of day (24-hour), space-padded to two
chars, 0 - 23
- %I hour of day-half (12-hour), 0-padded to two
chars, 01 - 12
- %l hour of day-half (12-hour), space-padded to two
chars, 1 - 12
- %M minute of hour, 0-padded to two chars,
00 - 59
- %S second of minute (without decimal part),
0-padded to two chars, 00 - 60
- %q picosecond of second, 0-padded to twelve chars,
000000000000 - 999999999999.
- %Q decimal point and fraction of second, up to 12
second decimals, without trailing zeros. For a whole number of
seconds, %Q omits the decimal point unless padding is
specified.
UTCTime and ZonedTime
For
UTCTime and
ZonedTime:
- %s number of whole seconds since the Unix epoch.
For times before the Unix epoch, this is a negative number. Note that
in %s.%q and %s%Q the decimals are positive, not
negative. For example, 0.9 seconds before the Unix epoch is formatted
as -1.1 with %s%Q.
DayOfWeek
For
DayOfWeek (and
Day and
LocalTime and
ZonedTime and
UTCTime and
UniversalTime):
- %u day of week number for Week Date format,
1 (= Monday) - 7 (= Sunday)
- %w day of week number, 0 (= Sunday) -
6 (= Saturday)
- %a day of week, short form (snd from
wDays locale), Sun - Sat
- %A day of week, long form (fst from
wDays locale), Sunday -
Saturday
Month
For
Month (and
Day and
LocalTime and
ZonedTime and
UTCTime and
UniversalTime):
- %Y year, no padding. Note %0Y and
%_Y pad to four chars
- %y year of century, 0-padded to two chars,
00 - 99
- %C century, no padding. Note %0C and
%_C pad to two chars
- %B month name, long form (fst from
months locale), January -
December
- %b, %h month name, short form (snd
from months locale), Jan - Dec
- %m month of year, 0-padded to two chars,
01 - 12
Day
For
Day (and
LocalTime and
ZonedTime and
UTCTime and
UniversalTime):
- %D same as %m/%d/%y
- %F same as %Y-%m-%d
- %x as dateFmt locale (e.g.
%m/%d/%y)
- %d day of month, 0-padded to two chars,
01 - 31
- %e day of month, space-padded to two chars,
1 - 31
- %j day of year, 0-padded to three chars,
001 - 366
- %f century for Week Date format, no padding. Note
%0f and %_f pad to two chars
- %V week of year for Week Date format, 0-padded to
two chars, 01 - 53
- %U week of year where weeks start on Sunday (as
sundayStartWeek), 0-padded to two chars, 00 -
53
- %W week of year where weeks start on Monday (as
mondayStartWeek), 0-padded to two chars, 00 -
53
Duration types
The specifiers for
DiffTime,
NominalDiffTime,
CalendarDiffDays, and
CalendarDiffTime are
semantically separate from the other types. Specifiers on negative
time differences will generally be negative (think
rem rather
than
mod).
NominalDiffTime and DiffTime
Note that a "minute" of
DiffTime is simply 60 SI seconds,
rather than a minute of civil time. Use
NominalDiffTime to
work with civil time, ignoring any leap seconds.
For
NominalDiffTime and
DiffTime:
- %w total whole weeks
- %d total whole days
- %D whole days of week
- %h total whole hours
- %H whole hours of day
- %m total whole minutes
- %M whole minutes of hour
- %s total whole seconds
- %Es total seconds, with decimal point and up to
<width> (default 12) decimal places, without trailing zeros. For
a whole number of seconds, %Es omits the decimal point unless
padding is specified.
- %0Es total seconds, with decimal point and
<width> (default 12) decimal places.
- %S whole seconds of minute
- %ES seconds of minute, with decimal point and up
to <width> (default 12) decimal places, without trailing zeros.
For a whole number of seconds, %ES omits the decimal point
unless padding is specified.
- %0ES seconds of minute as two digits, with decimal
point and <width> (default 12) decimal places.
CalendarDiffDays
For
CalendarDiffDays (and
CalendarDiffTime):
- %y total years
- %b total months
- %B months of year
- %w total weeks, not including months
- %d total days, not including months
- %D days of week
CalendarDiffTime
For
CalendarDiffTime:
- %h total hours, not including months
- %H hours of day
- %m total minutes, not including months
- %M minutes of hour
- %s total whole seconds, not including months
- %Es total seconds, not including months, with
decimal point and up to <width> (default 12) decimal places,
without trailing zeros. For a whole number of seconds, %Es
omits the decimal point unless padding is specified.
- %0Es total seconds, not including months, with
decimal point and <width> (default 12) decimal places.
- %S whole seconds of minute
- %ES seconds of minute, with decimal point and up
to <width> (default 12) decimal places, without trailing zeros.
For a whole number of seconds, %ES omits the decimal point
unless padding is specified.
- %0ES seconds of minute as two digits, with decimal
point and <width> (default 12) decimal places.
Format a
FormatTime instance value according to a template
string.
These formatting template codes are intended to be compatible with
glibc strftime() function, following
Data.Time.Format, which follows
formatCalendarTime from
the
old-time package. Codes which differ from
strftime() are marked as
EXTENSION.
Show/Parse template string spec
For all types
- %z RFC 822/ISO 8601:1988 style numeric time zone
(e.g., "-0600" or "+0100")
- %N ISO 8601 style numeric time zone (e.g.,
"-06:00" or "+01:00") EXTENSION
- %Z timezone name
- %c The preferred calendar time representation for
the current locale. As dateTimeFmt locale (e.g.
%a %b %e %H:%M:%S %Z %Y)
- %T same as %H:%M:%S
- %X The preferred time of day representation for
the current locale. As timeFmt locale (e.g.
%H:%M:%S)
- %r The complete calendar time using the AM/PM
format of the current locale. As time12Fmt locale
(e.g. %I:%M:%S %p)
- %P day-half of day from (amPm
locale), converted to lowercase, "am",
"pm"
- %p day-half of day from (amPm
locale), "AM", "PM"
- %H hour of day (24-hour), 0-padded to two chars,
"00"–"23"
- %k hour of day (24-hour), space-padded to two
chars, " 0"–"23"
- %I hour of day-half (12-hour), 0-padded to two
chars, "01"–"12"
- %l hour of day-half (12-hour), space-padded to two
chars, " 1"–"12"
- %M minute of hour, 0-padded to two chars,
"00"–"59"
- %S second of minute (without decimal part),
0-padded to two chars, "00"–"60"
- %q picosecond of second, 0-padded to twelve chars,
"000000000000"–"999999999999". EXTENSION
- %v microsecond of second, 0-padded to six chars,
"000000"–"999999". EXTENSION
- %Q decimal point and fraction of second, up to 6
second decimals, without trailing zeros. For a whole number of
seconds, %Q produces the empty string.
EXTENSION
- %s number of whole seconds since the Unix epoch.
For times before the Unix epoch, this is a negative number. Note that
in %s.%q and %s%Q the decimals are
positive, not negative. For example, 0.9 seconds before the Unix epoch
is formatted as "-1.1" with %s%Q.
- %F same as %Y-%m-%d
- %x as dateFmt locale (e.g.
%m/%d/%y)
- %Y year, no padding.
- %y year of century, 0-padded to two chars,
"00"–"99"
- %C century, no padding.
- %B month name, long form (fst from
months locale),
"January"–"December"
- %b, %h month name, short form (snd
from months locale),
"Jan"–"Dec"
- %m month of year, 0-padded to two chars,
"01"–"12"
- %d day of month, 0-padded to two chars,
"01"–"31"
- %e day of month, space-padded to two chars, "
1"–"31"
- %j day of year, 0-padded to three chars,
"001"–"366"
- %G year for Week Date format, no padding.
- %g year of century for Week Date format, 0-padded
to two chars, "00"–"99"
- %f century for Week Date format, no padding.
EXTENSION
- %V week of year for Week Date format, 0-padded to
two chars, "01"–"53"
- %u day of week for Week Date format,
"1"–"7"
- %a day of week, short form (snd from
wDays locale), "Sun"–"Sat"
- %A day of week, long form (fst from
wDays locale),
"Sunday"–"Saturday"
- %U week of year where weeks start on Sunday (as
sundayStartWeek), 0-padded to two chars,
"00"–"53"
- %w day of week number, "0" (= Sunday) –
"6" (= Saturday)
- %W week of year where weeks start on Monday (as
mondayStartWeek), 0-padded to two chars,
"00"–"53"
Examples
> formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%N" $ mkUTCTime 2015 1 15 12 34 56.78
"2015-01-15T12:34:56+00:00"
> formatTime defaultTimeLocale "%a, %_d %b %Y %H:%M:%S %Z" $ mkUTCTime 2015 1 15 12 34 56.78
"Thu, 15 Jan 2015 12:34:56 UTC"
YYYY-MM-DD hh:mm:ss.000000
> formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S.%v" $ mkUTCTime 2015 1 15 12 34 56.78
"2015-01-15 12:34:56.780000"
Format the times using a comma, which is certainly only correct in
German locale.
All instances of this class may be formatted by
formatTime.
formats time differences using local conventions and a formatting
string. The formatting string is that understood by the ISO C
strftime() function.
Format the time as describe in the Apache combined log format.
http://httpd.apache.org/docs/2.2/logs.html#combined
The format is: [day
monthyear:hour:minute:second zone] day =
2*digit month = 3*letter year = 4*digit hour = 2*digit minute =
2*digit second = 2*digit zone = (
+ |
-) 4*digit