Question

I feel as if I have poured over nearly all of the documentation regarding dates in JS and GAS. Especially concerning DST issues. Since I have not had a problem like this until the DST change. I think I am missing something simple. The problem is that despite messing with all of the settings the hours on my date output from the format utility are still incorrect. Below is a screen shot of the debugger and a snippet of the code i am running. The value 'date' is the one that I am concerned with. It is created within the script on line 53.

var date = new Date(); //line 53
date = Utilities.formatDate(date, "Chicago/America", "MM/dd/yyyy HH:mm:ss zzzz"); //line 61

I am based in KC. (Central Time or UTC-06:00 or whatever).

I have a feeling this is going to be a face palm moment for me but oh well! Thank you for any and all help!

Debugging output

Was it helpful?

Solution

what I usually use without any issue is simply that :

  var FUS1=new Date(dateObject).toString().substr(25,6)+":00";// get the timeZone part of the string coming from the date you are working on (an event)
  dateString = Utilities.formatDate(dateObject, FUS1, "MM/dd/yyyy HH:mm:ss");// use it in formatDate and it will have the right value for every season...

note that you were using date 2 times in your example code :once as a string result and once as a date object in the same line...

Edit following your comment :

assuming for example that the datestamp is in A2, the following code should return the right time.

  var date = SpreadsheetApp.getActiveSheet().getRange('A2').getValue();
  var FUS1=new Date(date).toString().substr(25,6)+":00";
  dateString = Utilities.formatDate(date, FUS1, "MM/dd/yyyy HH:mm:ss");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top