Swapnil Harde
Swapnil Harde

Reputation: 43

How to convert local date-time string to Unix timestamp (GMT)?

time_var="6/23/2016 3:20:00 AM"

(this is in EDT)

We need to get unix timestamp for this variable after converting its value to GMT.

Upvotes: 1

Views: 403

Answers (1)

fedorqui
fedorqui

Reputation: 289735

Just use the -u flag while passing the date with -d:

$ time_var="6/23/2016 3:20:00 AM"
$ date -d"$time_var EDT" -u
Thu Jun 23 07:20:00 UTC 2016

Note I also appended EDT to your date.

From man date:

   -d, --date=STRING
          display time described by STRING, not 'now'
   -u, --utc, --universal
          print or set Coordinated Universal Time

Upvotes: 1

Related Questions