How-to: strftime format codes

Common date and time string formats

FormatDescription
%%A literal %.
%aThe locale’s abbreviated weekday name (Sun..Sat).
%AThe locale’s full weekday name (Sunday..Saturday).
%BThe locale’s full month name (January..December).
%b or %hThe locale’s abbreviated month name (Jan..Dec).
%cThe locale’s default/preferred date and time representation.
%CThe century (a year divided by 100 and truncated to an integer) as a decimal number (00..99).
%dThe day of the month as a decimal number (01..31).
%DThe date in the format %m/%d/%y (MM/DD/YY). Note that the United States uses MM/DD/YY while everyone else uses DD/MM/YY, so this format is ambiguous and should be avoided. Use %F instead, since it’s a recognized standard and it sorts well.
%eThe day of month as a blank padded decimal number ( 1..31).
%FThe date in the format %Y-%m-%d (the ISO 8601 date format: CCYY-MM-DD); except when it’s the full month name, as on HP-UX.
%gThe two-digit year corresponding to the %V week number (YY).
%GThe four-digit year corresponding to the %V week number (CCYY).
%HThe hour (24-hour clock) as a decimal number (00..23).
%h or %bThe locale’s abbreviated month name (Jan..Dec).
%IThe hour (12-hour clock) as a decimal number (01..12).
%jThe day of the year as a decimal number (001..366).
%kThe hour (24-hour clock) as a blank padded decimal number ( 0..23).
%lThe hour (12-hour clock) as a blank padded decimal number ( 1,12).
%mThe month as a decimal number (01..12).
%MThe minute as a decimal number (00..59).
%nA literal newline.
%NNanoseconds (000000000..999999999). [GNU]
%pThe locale’s equivalent of either "AM" or "PM".
%PThe locale’s equivalent of either "am" or "pm". [GNU]
%rThe locale’s representation of 12-hour clock time using AM/PM notation (HH:MM:SS AM/PM).
%RThe time in the format %H:%M (HH:MM).
%sThe number of seconds since the Epoch, UTC (January 1, 1970 at 00:00:00).
%SThe second as a decimal number (00..61). The range of seconds is (00-61) instead of (00-59) to allow for the periodic occurrence of leap seconds and double leap seconds.
%tA literal tab.
%TThe time in the format %H:%M:%S (HH:MM:SS).
%uThe weekday (Monday as the first day of the week) as a decimal number (1..7).
%UThe week number of the year (Sunday as the first day of the week) as a decimal number (00..53).
%vThe date in the format %e-%b-%Y (D-MMM-CCYY). [Not standard]
%VThe week number of the year (Monday as the first day of the week) as a decimal number (01..53). According to ISO 8601 the week containing January 1 is week 1 if it has four or more days in the new year, otherwise it is week 53 of the previous year, and the next week is week 1. The year is given by the %G conversion specification.
%wThe weekday (Sunday as the first day of the week) as a decimal number (0..6).
%WThe week number of the year (Monday as the first day of the week) as a decimal number (00..53).
%xThe locale’s appropriate date representation.
%XThe locale’s appropriate time representation.
%yThe year without century as a decimal number (00..99).
%YThe year with century as a decimal number.
%zThe offset from UTC in the ISO 8601 format [-]hhmm.
%ZThe time zone name.



 
Copyright © 1999-2024 SS64.com
Some rights reserved