Table of Contents

Setting the date and time format

Below is an extract from the strftime documentation. Make sure that the length of the resulting date or time string is constant and does not exceed 21 characters.

Day

%dthe day of the month as a decimal number (01 to 31)
%elike %d, but a leading zero is replaced by a space

Month

%mthe month as a decimal number (01 to 12)
%bthe abbreviated month name

Year

%Ythe year as a decimal number including the century
%ylike %Y but without a century (00 to 99)

Hour

%Hthe hour as a number using a 24-hour clock (00 to 23)
%klike %H, but single digits are preceded by a blank
%Ithe hour as a number using a 12-hour clock (01 to 12)
%l(letter el) like %I but single digits are preceded by a blank
%p either AM or PM according to the given time value, or the corresponding strings for the current locale. Noon is treated as pm and midnight as am
%Plike %p but in lowercase

Minutes and seconds

%Mthe minute as a decimal number (00 to 59)
%Sthe second as a number (00 to 60)

Other

%%a literal % character

Examples

%H:%M13:59
%l:%M:%S%P1:59:07pm

Notes: