technology as-is

Linux Tip : Convert date time to Unix Time (Epoch)


Simple script to covert  regular  date time to unix epoch time format  (UTC)


#If date is passed without time then its assumed as midnight  00:00:00 for that day.

$sepoch=$(date “+%s” -d “$dat”)

$echo $sepoch

will return 1420156800

#If you need for specific datetime, then add time (24 h format)

$sepoch=$(date “+%s” -d “$dat  13:15:00”)

$echo $sepoch

will return 1420204500

This can be validated using

Leave a Reply

Required fields are marked *.