I've tried a lot from this community but it seems like there's no hyper specific scenario for my case.
So basically I have a string in the format of yyyy-mm-dd. I use date methods to adjust it and add time on the date to make it more specific. I want to convert it to timestamp while ignoring the client computer's current timezone (or using UTC timezone).
I have this code:
function getTimestampRange(sparams, eparams){
sparams = "2018-11-12", eparams = "2018-11-13"; //sample param values
const start = sparams.split("-");
const end = eparams.split("-");
const startDate = new Date(start[0], start[1] - 1, start[2]);
const endDate = new Date(end[0], end[1] - 1, end[2]);
endDate.setHours(23);
endDate.setMinutes(59);
endDate.setSeconds(59);
//startDate is 2018-11-12 00:00:00 and endDate is 2018-11-13 23:59:59
const startTS = startDate.getTime() / 1000;
const endTS = endDate.getTime() / 1000;
return [startTS, endTS]
}
This is all fine and dandy but the problem is, I'm getting the timestamp relative to my computer's timezone. (GMT+9). So my epoch is the 9th hour of 1970-01-01. Which is not what I need. I need the GMT+0 UTC timestamp.
In this scenario, I'd get 1541948400 and 1542121199, start and end respectively; where I should be getting 1541980800 and 1542153599.
Tasukete kudasai