+

Search Tips   |   Advanced Search

StrfTime format conversions

The format used when using the %{format}t log parameter is based on the non-extended BSD strftime(3) time conversion functions. The parameters specifically supported, and sample output, are listed in the following table.

Selected locale-specific parameters are supported as American English only. Specifically, the order in which month, day, and year appear, and perhaps the ordering of other items, remain American English in all locales. The spelling of words such as the day of the week, or the name of the month, and the timezone will be locale-correct.

Conversion string Description Example
%A Replaced by national representation of the full weekday name.

"Thursday"

%a Replaced by national representation of the abbreviated weekday.

"Thu"

%B Replaced by national representation of the full month name.

"September"

%b Replaced by national representation of the abbreviated month.

"Sep"

%C Year, divided by 100 (i.e. the century).

"20"

%c Replaced by national representation of time and date.

"Thu Sep 25 22:32:00 EDT"

%D Equivalent to %m/%d/%y

"09/25/08"

%d Replaced by the day of the month as a decimal number (01-31).

"25"

%e Replaced by the day of the month as a decimal number (1-31).

"25"

%F Equivalent to %Y-%m-%d.

"2008-09-25"

%G* The ISO 8601 week-based year (see NOTES) with century as a decimal number. The 4-digit year corresponds to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead.

"2008"

%g* Replaced by the same year as in %G, but as a decimal number without century (00-99).

"08"

%H Replaced by the hour (24-hour clock) as a decimal number (00-23).

"22"

%h Equivalent to %b.

"Sep"

%I Replaced by the hour (12-hour clock) as a decimal number (01-12).

"10"

%j Replaced by the day of the year as a decimal number (001-366).

"269"

%k Replaced by the hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank.

"22 (or '1' for 1am"

%l Replaced by the hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank.

"10"

%M Replaced by the minute as a decimal number (00-59).

"32"

%m Replaced by the month as a decimal number (01-12).

"09"

%n Replaced by a newline character.


%P Replaced by AM or PM.

"PM"

%R Equivalent to %H:%M.

"22:32"

%r Equivalent to %I:%M:%S %p .

"10:32:00 pm"

%S Replaced by the second as a decimal number (00-60).

"00"

%s Replaced by the number of seconds since the Epoch, UTC (see mktime(3)).

"1222396320"

%T Equivalent to %H:%M:%S

"22:32:00"

%t Replaced by a tab character.

%U Replaced by the week number of the year (Sunday as the first day of the week) as a decimal number (00-53).

"38"

%u Replaced by the weekday (Monday as the first day of the week) as a decimal number (1-7).

"4"

%V* Replaced by the week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1.

"39"

%v Equivalent to %e-%b-%Y.

"25-Sep-2008"

%W Replaced by the week number of the year (Monday as the first day of the week) as a decimal number (00-53).

"38"

%w Replaced by the weekday (Sunday as the first day of the week) as a decimal number (0-6).

"4"

%X Replaced by national representation of the time.

"22:32:00"

%x Replaced by national representation of the date.

"09/25/08"

%Y Replaced by the year with century as a decimal number.

"2008"

%y Replaced by the year without century as a decimal number.

"08"

%Z Replaced by the time zone name.

"EDT"

%z Replaced by the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign or west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).

"-0500"

%+ Replaced by national representation of the date and time (the format is similar to that produced by date(1)).

"Thu Sep 25 22:32:00 EDT"

%1 Milliseconds, rounded to three places, with leading zeros. Note: this is a departure from the strftime format, which does not represent milliseconds.

"000"

%% Replaced by '%'

%

* %G, %g, and %V yield values [are] calculated from the week-based year defined by the ISO 8601 standard. In this system, weeks start on a Monday, and are numbered from 01, for the first week, up to 52 or 53, for the last week. Week 1 is the first week where four or more days fall within the new year. Or, synonymously, week 01 is: the first week of the year containing a Thursday; or, the week that has 4 January in it. When three of fewer days of the first calendar week of the new year fall within that year, then the ISO 8601 week-based system counts those days as part of week 53 of the preceding year. For example, 1 January 2010 is a Friday, meaning that just three days of that calendar week fall in 2010. Thus, the ISO 8601 week-based system considers these days to be part of week 53 (%V) of the year 2009 (%G) ; week 01 of ISO 8601 year 2010 starts on Thursday, 4 January 2010.

%{The time is: %X.%1%nThe date is: %x}t 

This input yields the following output: The time is: 22:32:00.000 The date is: 09/25/08


Related:

  • Custom log file format
  • Configure custom logs
  • StrfTime format conversions