I've been working on this for a long time and haven't quite found anything that fits what I need.
Right now, I have an array of dates- all of them look like this -
Sun Mar 31 2013 00:00:00 GMT+0700 (ICT).
I'm looking for a way to convert that into
1364688000
Only through Google Script.
How would you go about doing this?
=(A3-DATE(1970,1,1))*86400
With A3 being something like "2/20/2018"
The getTime()
method applied to a date returns the number of milliseconds since the epoch reference in JavaScript, ie what you are looking for.
Logger.log(new Date(2013,3,31,0,0,0,0).getTime());
Your value is in seconds, so we can divide /1000
but the value you are showing is not correct, result has an offset of 31 days in GMT 0 ... How are you getting the value 1364688000
?
test code (script properties in UTC (GMT 0 without daylight savings)
function timeInMsSinceOrigin(){
var val = new Date(2013,3,31,0,0,0,0).getTime()/1000;// in seconds
var offset = val-1364688000; //in seconds too
Logger.log('value = '+val+ ' offset : '+offset/3600+' hours ='+offset/(3600*24)+' days');
}
Logger result : value = 1367366400 offset : 744 hours =31 days
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With