Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get UTC time in seconds

It looks like I can't manage to get the bash UTC date in second. I'm in Sydney so + 10hours UTC time

 date  Thu Jul 3 17:28:19 WST 2014   date -u  Thu Jul 3 07:28:20 UTC 2014 

But when I tried to convert it, I'm getting the same result which is not UTC time

 date +%s  1404372514   date -u +%s  1404372515 

What am I missing here?


After getting an answer saying date +%s was returning UTC time, here are more details about the problem I'm facing now.

I'm trying to compare a date written in a file with python. This date is written in seconds in UTC time. And the bash date +%s doesn't give me the same one. Actually if I'm doing in python time.asctime(time.localtime(date_in_seconds_from_bash)), I get the current time of Sydney, not UTC. I don't understand.

like image 613
Romanzo Criminale Avatar asked Jul 03 '14 07:07

Romanzo Criminale


People also ask

How do you convert UTC to seconds?

Dp = duration(hh,mm:mm,ss:ss); tp= (minutes(D))*60; Guidance required to make it into a time series which is generic in way that milli seconds are taken into account as well.

How do I get UTC timestamp?

Use the getTime() method to get a UTC timestamp, e.g. new Date(). getTime() . The method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation. Calling the method from any time zone returns the same UTC timestamp.

What is UTC timestamp now?

Current time: 14:10:11 UTC. UTC is replaced with Z that is the zero UTC offset. UTC time in ISO-8601 is 14:10:11Z.

How do you find the timestamp in seconds?

getTime(); long durationinSeconds2 = timeInMillisSinceEpoch123 / 1000; System. out. println("Time in Seconds UTC: " + durationinSeconds2);

How do I get the UTC time?

If you want UTC, use time.gmtime () rather than time.localtime (). As JamesNoonan33's answer says, the output of date +%s is timezone invariant, so date +%s is exactly equivalent to date -u +%s. It prints the number of seconds since the "epoch", which is 1970-01-01 00:00:00 UTC. The output you show in your question is entirely consistent with that:

What is the current UTC timestamp in seconds?

UTC Timestamp Time in Seconds. Current UTC timestamp to time is 15:39:30. This is the page for those who want to learn current UTC timestamp. It can be useful information for anyone who needs to spot the current moment of time. It is valid for any UTC time zone and can be used in a few kinds of UTC time formats.

What is UTC time in JavaScript?

UTC (Universal Time Coordinated) is the time set by the World Time Standard. UTC time is the same as GMT time (Greenwich Mean Time). All JavaScript getUTC methods assume that the date is of local time. The seconds of the date (0 to 59).

What is the difference between UTC and GMT?

UTC (Universal Time Coordinated) is the time set by the World Time Standard. UTC time is the same as GMT time (Greenwich Mean Time). All JavaScript getUTC methods assume that the date is of local time. The seconds of the date (0 to 59). getUTCSeconds () is an ECMAScript1 (ES1) feature.


2 Answers

I bet this is what was intended as a result.

$ date -u --date=@1404372514 Thu Jul  3 07:28:34 UTC 2014 
like image 34
Derek Boonstra Avatar answered Sep 21 '22 06:09

Derek Boonstra


I believe +%s is seconds since epoch. It's timezone invariant.

like image 90
JamesNoonan33 Avatar answered Sep 20 '22 06:09

JamesNoonan33