Flash Notes
Commands - Date conversion
• How to get the current date (system date) in seconds since the epoch (01/01/1970) ?
Solution
date '+%s'
Example 1
$ date '+%s' 1406129320
Man pages
-
date(1) - Debian 7.5.0 (amd64)
date(1) - Debian 7.4.0 (amd64)
date(1) - Debian 7.3 (amd64)
date(1) - Debian 7.2.0 (amd64)
date(1) - Debian 7.1 (amd64)
• How to convert a date given in the ISO 8601 format into a date in seconds since the epoch (01/01/1970) ?
Solution
date -d date '+%s'
Example 1
$ date -d '2012/02/25' '+%s' 1330124400
Example 2
$ date -d '2012/02/25 06:26:57' '+%s' 1330147617
Man pages
-
http://man.flashnux.com/en/debian/7/7.5.0/man1/date.1.html
• How to convert a date given in the usual US format into a date in seconds since the epoch (01/01/1970) ?
Solution
date -d date '+%s'
Example 1
$ date -d '02/25/12' '+%s' 1330124400
Man pages
-
http://man.flashnux.com/en/debian/7/7.5.0/man1/date.1.html
• How to convert a date given in seconds since the epoch (01/01/1970) in standard format ?
Solution
date -d '@date_in_seconds'
Example 1
$ date -d '@1339832819' Sat Jun 16 09:46:59 CEST 2012
Man pages
-
http://man.flashnux.com/en/debian/7/7.5.0/man1/date.1.html
• How to convert a date in seconds since the epoch (01/01/1970) into a specified format date ?
Solution
date -d '@date' '+%specified_format'
Example 1
$ date -d '@1339832819' '+%m/%d/%Y %H:%M:%S' 2012-06-16 09:46:59
Man pages
-
http://man.flashnux.com/en/debian/7/7.5.0/man1/date.1.html