.TH DATEFMT 1 .SH NAME datefmt \- print the date and time in various formats .SH SYNOPSIS .B datefmt [ .B -t .I seconds ] .I format .SH DESCRIPTION .PP .I Datefmt prints the date at the current time according to .IR format , described below. With .I -t it will instead print the time at .IR seconds , the count of seconds since midnight on January 1, 1970. .PP .I Format is a string containing any number of date or time elements to print, each indicated by a .B % followed by a single character .IR verb , similar to a .IR print (2) specification but with no flags. Each verb corresponds to either a single date or time element, such as the month or seconds in a minute, a combination of them, such as the current date in a particular format, or a literal character output. The verbs which produce literal character output are for convenience in environments where quoting is difficult or tedius; characters not preceeded by a % are otherwise passed through. Unrecognized verbs are ignored. .SH VERBS .SS Basic values .in 6m .ta 4m .ti2m \fL%A\fR Full weekday name. .ti2m \fL%a\fR Abbreviated weekday name. .ti2m \fL%B\fR Full month name. .ti2m \fL%b\fR Abbreviated month name. .ti2m \fL%C\fR (year / 100) as a decimal number; single digits are preceded by a zero. .ti2m \fL%c\fR Time and date; equivalent to \fL%a %b %e %T %Y\fR. .ti2m \fL%D\fR Date; equivalent to \fL%m/%d/%y\fR. .ti2m \fL%d\fR Day of the month as a decimal number (01-31). .ti2m \fL%e\fR Day of the month as a decimal number (1-31); single digits are preceded by a blank. .ti2m \fL%F\fR Date; equivalent to \fL%Y-%m-%d\fR. .ti2m \fL%H\fR Hour (24-hour clock) as a decimal number (00-23). .ti2m \fL%h\fR Abbreviated month name; equivalent to \fL%b\fR. .ti2m \fL%I\fR Hour (12-hour clock) as a decimal number (01-12). .ti2m \fL%j\fR Day of the year as a decimal number (001-366). .ti2m \fL%k\fR Hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank. .ti2m \fL%l\fR Hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank. .ti2m \fL%M\fR Minute as a decimal number (00-59). .ti2m \fL%m\fR Month as a decimal number (01-12). .ti2m \fL%n\fR A newline. .ti2m \fL%p\fR Either "AM" or "PM" as appropriate. .ti2m \fL%R\fR Time; equivalent to \fL%H:%M\fR. .ti2m \fL%r\fR Time; equivalent to \fL%I:%M:%S %p\fR. .ti2m \fL%S\fR Second as a decimal number (00-60). .ti2m \fL%s\fR Number of seconds since the Epoch, UTC (see .IR time (2)). .ti2m \fL%T\fR Current time; equivalent to \fL%H:%M:%S\fR. .ti2m \fL%t\fR A tab. .ti2m \fL%u\fR Weekday (Monday as the first day of the week) as a decimal number (1-7). .ti2m \fL%v\fR Date; equivalent to \fL%e-%b-%Y\fR. .ti2m \fL%w\fR Weekday (Sunday as the first day of the week) as a decimal number (0-6). .ti2m \fL%X\fR Time; equivalent to \fL%T\fR. .ti2m \fL%x\fR Current date; equivalent to \fL%m/%d/%y\fR. .ti2m \fL%Y\fR Year with century as a decimal number. .ti2m \fL%y\fR Year without century as a decimal number (00-99). .ti2m \fL%Z\fR Time zone abbreviation. .ti2m \fL%z\fR Time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers). .SS Local additions .in 6m .ta 4m .ti2m \fL%+\fR Date and time (the format is similar to that produced by .IR date(1)). .ti2m \fL%,\fR Truncated Julian Day. .ti2m \fL%.\fR Truncated Julian Day with fractional days. .ti2m \fL%:\fR Like %z, but with a : between the hours and minutes. Useful for RFC 3339 dates. .SS Character literals .in 6m .ta 4m .ti2m \fL%%\fR A literal '%'. .ti2m \fL%n\fR A newline. .ti2m \fL%t\fR A tab character. .ti2m \fL% \fR (% followed by a space) A space. .PP .SH EXAMPLE .PP Show the current date and time in a human-friendly way: .EX :; datefmt '%a %b %e %T %Y%n' Sat Apr 13 05:45:45 2024 .EE This is equivalent to .LR "datefmt %r%n" . .SH SOURCE .B http://a.9srv.net/src/#datefmt for versions in both C and Limbo. .SH SEE ALSO .I mayan - a version for various Mayan calendars; .IR http://a.9srv.net/src/#mayan . .PP .I timestamp - prepend a timestamp to output lines, optionally using .IR datefmt ; .IR http://a.9srv.net/src/#timestamp . .SH BUGS It's unclear some version of this shouldn't just be in .IR date (1). .PP In POSIX terms, this always operates in the 'C' locale. .PP There sure are a lot of these.