martin
martin

Reputation: 11

converting 3 hours ago, 7 hours ago etc into unix timestamp

Hello Everyone          

Can anyone guide me how i can convert 4 hours ago, 3 hours ago etc into unix timestamp? It is often observed on many sites some time ago like 3 hours ago etc , i really need it to convert into unix timestamp, let me know if anyone have any idea?

Upvotes: 1

Views: 1627

Answers (2)

Martin
Martin

Reputation: 38289

From the command line, date can do this conversion for you:

date -d "3 hours ago" +"%s"

where +"%s" is a date format that simply means "print unix timestamp"

Upvotes: 2

smitec
smitec

Reputation: 3049

if it is always in the format "n Hours ago" you can convert n to an integer and then subtract 3600*n from the current unix timestamp.

Without knowing the language you are using it is hard to give a more detailed explanation.

Upvotes: 1

Related Questions