Formatting
To format a date, a parameter string beginning with a plus sign (+) is given. The formatting specifiers below are supported by most implementations.
Specifier | Description | Values or example |
---|---|---|
Day | ||
%a | weekday, abbreviated | Wed |
%A | weekday, full | Wednesday |
%d | day of the month, two digits, zero filled | 08 |
%e | day of the month | 8 |
%j | day of year, zero filled | 001–366 |
%u | day of week from Monday to Sunday | 1–7 |
%w | day of week from Sunday to Saturday | 0–6 |
Week | ||
%U | week number, Sunday as first day of week | 00–53 |
%W | week number, Monday as first day of week | 00–53 |
%V | ISO standard week of the year | 01–53 |
Month | ||
%m | two-digit month number | 01–12 |
%h | month name, abbreviated | Mar |
%b | month name, localised abbreviation | Mar |
%B | locale's full month, variable length | March |
Year | ||
%y | two-digit year | 00–99 |
%Y | four-digit year | 2014 |
%g | two-digit year corresponding to the %V week number | |
%G | four-digit year corresponding to the %V week number | |
Century | ||
%C | two century digits from year | 00–99 |
Date | ||
%D | mm/dd/yy | 03/19/14 |
%x | locale's date representation | 03/19/2014 |
%F | %Y-%m-%d | 2014-03-19 |
Hours | ||
%l | hour (12 hour) | 10 |
%I | hour (12 hour), zero-filled | 10 |
%k | hour (24 hour) | 10 |
%H | hour (24 hour), zero-padded | 10 |
%p | locale's upper case AM or PM (blank in many locales) | AM |
%P | locale's lower case am or pm | am |
Minutes | ||
%M | two-digit minute number | 52 |
Seconds | ||
%s | seconds since 00:00:00 1970-01-01 UTC (Unix epoch) | 1395226379 |
%S | two-digit second number | 00–60 (Includes 60 to accommodate a leap second) |
%N | nanoseconds | 000000000–999999999 |
Time | ||
%r | hours, minutes, seconds (12-hour clock) | 10:52:59 AM |
%R | hours, minutes (24 hour clock) | 10:52 |
%T | hours, minutes, seconds (24-hour clock) | 10:52:59 |
%X | locale's time representation | 11:07:26 AM |
Date and time | ||
%c | locale's date and time | Sat Nov 04 12:02:33 EST 1989 |
Time zone | ||
%z | RFC-822 style numeric time zone | -0500 |
%Z | time zone name; nothing if no time zone is determinable | EST, EDT |
literals: %n newline %% percent %t horizontal tab
By default, date normally fills numeric fields with zeroes. GNU date, but not BSD date, recognizes a modifier between the per cent sign (%) and the format specifier:
- hyphen (-): do not fill the field
- underscore (_): pad the field with spaces
TZ Specifies the time zone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used.
example
$ date "+%m/%d/%y" 7/4/06
$ date "+%Y%m%d" 20060704
To assign the time to a variable
$ START=`date '+%r'` $ echo $START 03:06:02 PM $ sleep 5 $ echo $START 03:06:02 PM
N.B. the variable has the time when it was assigned.
Yesterday assigned to variable
$ DATE=$(date -d yesterday +"%Y%m%d") $ echo $DATE 20060704
The TZ environment variable specifies the time zone. Valid values are in /usr/share/zoneinfo
$ TZ=GMT; echo "GMT: `date +\"%R (%Z)\"`" GMT: 12:30 (GMT) $ TZ=Europe/Stockholm; echo "Stockholm: `date +\"%R (%Z)\"`" Stockholm: 13:30 (CET) $ TZ=Asia/Kuala_Lumpur; echo "Kuala Lumpur: `date +\"%R (%Z)\"`" Kuala Lumpur: 20:30 (MYT) $ TZ=US/Central; echo "Dallas: `date +\"%R (%Z)\"`" Dallas: 07:30 (CDT)
Converting between time zones Example: What time is it in Moscow when it will be 17:35 in Los Angeles
$ TZ=Europe/Moscow date "+%F %R (%Z%z)" -d 'TZ="America/Los_Angeles" 17:35' 2013-03-22 04:35 (MSK+0400)
Other valid time strings
GNU date | BSD date | output |
---|---|---|
$ date +"%Y%m%d" -d sunday | $ date -v +sun +"%Y%m%d" | 20060709 |
$ date +"%Y%m%d" -d last-sunday | $ date -v -sun +"%Y%m%d" | 20060702 |
$ date +"%Y%m%d" -d last-week | $ date -v -1w +"%Y%m%d" | 20060627 |
$ date +"%Y%m%d" -d last-month | $ date -v -1m +"%Y%m%d" | 20060604 |
$ date +"%Y%m%d" -d last-year | $ date -v -1y +"%Y%m%d" | 20050704 |
$ date +"%Y%m%d" -d next-week | $ date -v 1w +"%Y%m%d" | 20060711 |
$ date +"%Y%m%d" -d next-month | $ date -v 1m +"%Y%m%d" | 20060804 |
$ date +"%Y%m%d" -d next-year | $ date -v 1y +"%Y%m%d" | 20070704 |
$ date +"%Y%m%d" -d "2 days ago" | $ date -v -2d +"%Y%m%d" | 20060702 |
$ date +"%Y%m%d" -d "2 months ago" | $ date -v -2m +"%Y%m%d" | 20060504 |
$ date +"%Y%m%d" -d "2 years ago" | $ date -v -2y +"%Y%m%d" | 20040704 |
To show the time in seconds since 1970-01-01 (Unix epoch):
$ date +"%s" -d "Fri Apr 24 13:14:39 CDT 2009" 1240596879
To convert Unix epoch time (seconds since 1970-01-01) to a human readable format:
$ date -d "UTC 1970-01-01 1240596879 secs" Fri Apr 24 13:14:39 CDT 2009
Or:
$ date -ud @1000000000 Sun Sep 9 01:46:40 UTC 2001
Roulette - The Game of Casino Roulette | Goyangfc
ReplyDeleteRoulette. 1 bet Casino. Roulette. Roulette. Casino. The 배팅 Game 알바로 모라타 of Casino 강원랜드여자 Roulette. Casino. The Game of Casino Roulette. Casino. The Game of Casino Roulette. Casino. The Game of 모모벳