In javascript we generally do
var date = new Date()
and if we want to increase and compare later
var newDate = date.setSeconds(1000)
now we can compare date < newDate or not
I am writing a gmail addon in that i need use similar kind of thing. How can do this in google script.
I tried to find it in the google script documentation but i am not able to find this. Can someone help me on this?
Apps Script still uses the JavaScript new Date()
definition for dates, though when you use date.setSeconds(1000)
the date gets converted to Unix time. Google uses Unix time in milliseconds.
Calling date.setSeconds()
changes the variable date even when calling it inside newDate = date.setSeconds(1000)
.
You can fix this by with:
function myFunction() {
var date = new Date()
var newDate = new Date(unixTimeConverter(date).setSeconds(1000));
}
function unixTimeConverter(n) {
return new Date(n);
}