I'm using JavaScript and trying to get GMT+0/UTC+0 time (otherwhise called Zulu time) in Unix format.
I've managed to get my local time in Unix format like this:
var datetime = new Date()
var unixtime = Math.floor(Number(datetime/1000));
but when I try to do the same with UTC time...
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);
it fails. I simply get my local time in Unix format.
You can run it live here: http://jsfiddle.net/wC8XH/1/ (Also on pastebin: http://pastebin.com/uDD5zUah)
This is an example of output:
2012-01-30 23:15:19 = 1327958119
2012-01-30 21:15:19 = 1327958119
Doing:
date -d "2012-01-30 21:15:19" +%s
on Linux gives me 1327950919, not 1327958119. The difference is 7200 seconds, which is 2 hours, which is my timezone (+0200).
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.
Am I missing something?