You can use Linux date command with different FORMAT option to format the date in Linux.
Example:
Get date on Linux in default format:
1 2 |
## default date ## returns Sun, May 24, 2020 7:18:38 PM |
Linux date FORMAT options with examples:
Get only three-letter day name in Linux:
1 2 |
## %a locale's abbreviated weekday name (e.g., Sun) date '+%a' ## returns Sun |
Get only day name in Linux:
1 2 |
## %A locale's full weekday name (e.g., Sunday) date '+%A' ## returns Sunday |
Get only three-letter month name in Linux:
1 2 3 4 |
## %b locale's abbreviated month name (e.g., Jan) date '+%b' ## returns May ## %h same as %b date '+%h' ## returns May |
Get only month name in Linux:
1 2 |
## %B locale's full month name (e.g., January) date '+%B' ## returns May |
Get locale date and time in Linux:
1 2 |
## %c locale's date and time (e.g., Thu Mar 3 23:05:25 2005) date '+%c' ## returns Sun, May 24, 2020 7:41:45 PM |
Get first two digits of current year in Linux:
1 2 |
## %C century; like %Y, except omit last two digits (e.g., 20) date '+%C' ## returns 20 |
Get current day of month in Linux:
1 2 3 4 |
## %d day of month (e.g., 01) date '+%d' ## returns 24 ## %e day of month, space padded; same as %_d date '+%e' ## returns 24 |
Get current date in mm/dd/yy format in Linux:
1 2 |
## %D date; same as %m/%d/%y date '+%D' ## returns 05/24/20 |
Get current date in yyyy-mm-dd format in Linux:
1 2 |
## %F full date; same as %Y-%m-%d date '+%F' ## returns 2020-05-24 |
Get last two digits of current year in Linux:
1 2 |
## %g last two digits of year of ISO week number date '+%g' ## returns 20 |
Get current hour in 24 hours format in Linux:
1 2 3 4 |
## %H hour (00..23) date '+%H' ## returns 19 ## %k hour, space padded ( 0..23); same as %_H date '+%k' ## returns 19 |
Get current hour in 12 hours format in Linux:
1 2 3 4 |
## %I hour (01..12) date '+%I' ## returns 07 ## %l hour, space padded ( 1..12); same as %_I date '+%l' ## returns 7 |
Get current day of year in Linux:
1 2 |
## %j day of year (001..366) date '+%j' ## returns 145 |
Get current month number in Linux:
1 2 |
## %m month (01..12) date '+%m' ## returns 05 |
Get current minute in Linux:
1 2 3 4 5 6 7 |
## %M minute (00..59) date '+%M' ## returns 52 ## %n a newline date '+Year=%Y%nMonth=%m' ## returns ## Year=2020 ## Month=05 |
Get current nanoseconds in Linux:
1 2 |
## %N nanoseconds (000000000..999999999) date '+%N' ## returns 258026200 |
Get current time with am pm in Linux:
1 2 3 4 5 6 |
## %p locale's equivalent of either AM or PM; blank if not known date '+%l %p' ## returns 7 PM ## %P like %p, but lower case date '+%l %P' ## returns 7 pm ## %r locale's 12-hour clock time (e.g., 11:11:04 PM) date '+%r' ## returns 7:56:55 PM |
Get current hour minute in Linux:
1 2 |
## %R 24-hour hour and minute; same as %H:%M date '+%R' ## returns 19:57 |
Get current time since epoch in Linux:
1 2 |
## %s seconds since 1970-01-01 00:00:00 UTC date '+%s' ## 1590330464 |
Get current seconds in Linux:
1 2 |
## %S second (00..60) date '+%S' ## returns 10 |
Get current day of week in number in Linux:
1 2 |
## %u day of week (1..7); 1 is Monday date '+%u' ## returns 7 |
Get current week number of year in Linux:
1 2 3 4 5 6 7 8 |
## %U week number of year, with Sunday as first day of week (00..53) date '+%U' ## returns 21 ## %V ISO week number, with Monday as first day of week (01..53) date '+%V' ## returns 21 ## %w day of week (0..6); 0 is Sunday date '+%w' ## returns 0 ## %W week number of year, with Monday as first day of week (00..53) date '+%W' ## returns 20 |
Get current year in Linux:
1 2 |
## %Y year date '+%Y' ## returns 2020 |
Get current date with timezone in Linux:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
## %z +hhmm numeric time zone (e.g., -0400) date '+%z' ## returns +0530 ## %:z +hh:mm numeric time zone (e.g., -04:00) date '+%:z' ## returns +05:30 ## %::z +hh:mm:ss numeric time zone (e.g., -04:00:00) date '+%::z' ## returns +05:30:00 ## %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30) date '+%:::z' ## returns +05:30 ## %Z alphabetic time zone abbreviation (e.g., EDT) date '+%Z' ## returns IST |