13

I saw this date command:

date -d @1332468005 '+%Y-%m-%d %H:%M:%S'

Resulting in :

2012-03-22 22:00:05

How can I convert it back from 2012-03-22 22:00:05 to 1332468005 with bash shell?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Uncelvel
  • 305
  • 1
  • 2
  • 9

2 Answers2

23

man date will give you the details of how to use the date command.

To convert long date in standard format into Unix epoc time (%s): date -d '2012-03-22 22:00:05 EDT' +%s

David
  • 602
  • 3
  • 3
7

MacOS - date -j -f "%Y:%m:%d %H:%M:%S" '2012:03:22 22:00:05' +%s

demmonico
  • 71
  • 1
  • 2