0

I have a response which is returning the dates as YYYY-MM-DD HH:MM:SS format. However, due to timezones issues, I am trying to convert these in to GMT format.

I tried directly converting them but Google script always takes these as Text and thus returns Jan 1, 1970 as the output when using a Date object.

I tried adding the timezone offset to the string and then converting, but to no avail.

Is there any way I can convert this format into a proper date or directly convert it into GMT?

dateValue = '2019-02-20 18:30:00'    
var tempDate = dateValue + ' +0530';
dateValue = new Date(tempDate)

I'd expect the outcome to be returned as a date, which I can then convert to GMT format

1 Answers1

0

How about this?

function splitItUp() {
  var dts="2019-02-18 19:52:14";
  var tA=dts.split(' ');
  var tD=tA[0].split('-');
  var tT=tA[1].split(':');
  var dt=new Date(Number(tD[0]),Number(tD[1])-1,Number(tD[2]),Number(tT[0]),Number(tT[1]),Number(tT[2]))
  Logger.log(dt);
}
Cooper
  • 59,616
  • 6
  • 23
  • 54