Note that there are some explanatory texts on larger screens.

plurals
  1. POGMT/UTC (not local) time in Unix format
    text
    copied!<p>I'm using JavaScript and trying to get GMT+0/UTC+0 time (otherwhise called Zulu time) in Unix format.</p> <p>I've managed to get my local time in Unix format like this:</p> <pre><code>var datetime = new Date() var unixtime = Math.floor(Number(datetime/1000)); </code></pre> <p>but when I try to do the same with UTC time...</p> <pre><code>var datetime = new Date() var year = datetime.getUTCFullYear() var month = datetime.getUTCMonth() var day = datetime.getUTCDate() var hours = datetime.getUTCHours() var minutes = datetime.getUTCMinutes() var seconds = datetime.getUTCSeconds() var unixtime = (Date.UTC(year,month,day,hours,minutes,seconds,00)/1000); </code></pre> <p>it fails. I simply get my local time in Unix format.</p> <p>You can run it live here: <a href="http://jsfiddle.net/wC8XH/1/" rel="nofollow">http://jsfiddle.net/wC8XH/1/</a> (Also on pastebin: <a href="http://pastebin.com/uDD5zUah" rel="nofollow">http://pastebin.com/uDD5zUah</a>)</p> <p>This is an example of output:</p> <pre><code>2012-01-30 23:15:19 = 1327958119 2012-01-30 21:15:19 = 1327958119 </code></pre> <p>Doing:</p> <pre><code>date -d "2012-01-30 21:15:19" +%s </code></pre> <p>on Linux gives me 1327950919, not 1327958119. The difference is 7200 seconds, which is 2 hours, which is my timezone (+0200).</p> <p>So I can get UTC+0 time if I simply want it in human readable format but when I request Date.UTC to convert that into Unix format, it instead chooses to convert my local time.</p> <p>Am I missing something?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload