HomeLinux

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

Like Tweet Pin it Share Share Email

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

$dat=’01/02/2015′

#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  www.epochconverter.com

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *