Page 2 of 2

Convert _CreatedAt - Javascript Assistance

Posted: Mon Sep 22, 2014 5:22 pm
by Mike6979865

Thank you, it worked. I had to also change var goalTimeZone = -7; to var goalTimeZone = -14; to get the Pacific Standard Time (California Time)

Regards, and thank you so much for your help.


Convert _CreatedAt - Javascript Assistance

Posted: Mon Apr 13, 2015 10:10 pm
by Mike6979865

Hi,
When it's daylight saving, I have to manually adjust the time in the code by one hour. I'm thinking to apply the following:

Get current month
If month is between 3 and 11 then goal time zone = -14
else - 16

Can you please help me with that? Does that seem like a solution? The problem is that daylight savings change each year...


Convert _CreatedAt - Javascript Assistance

Posted: Wed Apr 15, 2015 3:20 am
by Yurii Orishchuk

Hi Mike,

Yes it's possible. But i guess you need to narrow daylight period criteria..

Here is a requested code:

pre

var stringDate = value;
var arrDate = stringDate.split(/[- :]/);
var date = new Date(arrDate[0], arrDate[1]-1, arrDate[2], arrDate[3], arrDate[4]);

//You can change timezone here;
var goalTimeZone = -16;

var month = date.getMonth() + 1;
if(month 3 && month < 11)
goalTimeZone = -14;

date = new Date(date&#46;getTime() + (goalTimeZone * 3600 * 1000));
console&#46;log(date);
return date&#46;toUTCString()&#46;replace(/GMT/gi, "");

/pre

Regards.