Skip to content

Instantly share code, notes, and snippets.

@nikreiman
Created November 30, 2011 08:06
Show Gist options
  • Save nikreiman/1408399 to your computer and use it in GitHub Desktop.
Save nikreiman/1408399 to your computer and use it in GitHub Desktop.
Unix date formatting cheat sheet
Day
---
%a weekday, abbreviated Tue
%A weekday, full Tuesday
%d day of the month (dd), zero padded 22
%e day of the month (dd) 22
%j day of year, zero padded 001-366
%u day of week starting with Monday (1), i.e. mtwtfss 2
%w day of week starting with Sunday (0), i.e. smtwtfs 2
Week
---
%U week number Sunday as first day of week 00–53
%W week number Monday as first day of week 01–53
%V week of the year 01–53
Month
-----
%m mm month 11
%h Mon Nov
%b Mon, locale's abbreviated Nov
%B locale's full month, variable length November
Year
---
%y yy two digit year 00–99
%Y ccyy year 2011
%g 2-digit year corresponding to the %V week number
%G 4-digit year corresponding to the %V week number
Century
-------
%C cc century 00–99
Date
----
%D mm/dd/yy 11/22/11
%x locale's date representation (mm/dd/yy) 11/22/2011
%F %Y-%m-%d 2011-11-22
Hours
-----
%l (Lowercase L) hour (12 hour clock) 7
%I (Uppercase I) hour (12 hour clock) zero padded 07
%k hour (24 hour clock) 7
%H hour (24 hour clock) zero padded 07
%p locale's upper case AM or PM (blank in many locales) AM
%P locale's lower case am or pm am
Minutes
-------
%M MM minutes 47
Seconds
-------
%s seconds since 00:00:00 1970-01-01 UTC (Unix epoch) 1321948063
%S SS second 00–60
(The 60 is necessary to accommodate a leap second)
%N nanoseconds 000000000–999999999
Time
----
%r hours, minutes, seconds (12-hour clock) 07:47:43 AM
%R hours, minutes (24 hour clock) hh:mm e.g. 07:47
%T hours, minutes, seconds (24-hour clock) 07:47:43
%X locale's time representation (%H:%M:%S)
Date and Time
-------------
%c locale's date and time Sat Nov 04 12:02:33 EST 1989
Time zone
---------
%z -zzzz RFC-822 style numeric timezone -0500
%Z time zone (e.g., EDT) nothing if no time zone is determinable EST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment