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

• 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

• 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

• 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

• 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