Pages

Wednesday, 19 September 2012

Date

Date to epoch

The current date and time

 [root@localhost scripts]# date
Wed Sep 19 11:13:38 PDT 2012


The current date in terms of epoch. The --date="Wed Sep 19 11:13:38 PDT 2012" is copied from the output of date command.

[root@localhost scripts]# date --date="Wed Sep 19 11:13:38 PDT 2012" +%s
1348078418


Other acceptable format

[root@localhost scripts]# date --date="2012-09-19 11:13:38" +%s
1348078418


[root@localhost scripts]# date -d "2012-09-19 11:13:38" +%s
1348078418

If the time is omitted,  the time is implied as 00:00:00

[root@localhost scripts]# date --date="2012-09-19" +%s
1348038000


If the date is omitted, it is assumed to be the current date.

[root@localhost scripts]# date --date="10:57:04" +%s
1348077424

Add a number of seconds to a certain date in "YYYY-MM-DD HH:MM:SS"

[root@localhost scripts]# date -d  "2012-09-19 00:00:10 40 seconds"
Wed Sep 19 00:00:50 PDT 2012

[root@localhost scripts]# date -d  "2012-09-19 00:00:10 40 seconds" +%s
1348038050

Epoch to Date

Epoch time is the number of second from 1970-01-01 00:00:00 UTC
[root@localhost scripts]# date -d "1970-01-01 UTC 00:00:00 1348038050 seconds"
Wed Sep 19 00:00:50 PDT 2012



Todo: date diff, Timezone, Convert time for different TZ

No comments:

Post a Comment