You are viewing limited content. For full access, please sign in.

Question

Question

jquery to convert to specific time zone with daylight savings logic

asked on August 20, 2017

I have a Forms user that wants to convert the actual time a form was started to CST (not submitted) due to regulatory requirements- I am able to accomplish this in code using utc with an offset but this will not work when we move away from daylight savings time.  Does anyone know how to account for daylight savings time when converting utc in jquery?  I have attached my current code.  Thank you in advance!

$(document).ready(function(){
d = new Date();
localTime = d.getTime();
localOffset = d.getTimezoneOffset() * 60000;
utc = localTime + localOffset;
offset = -5;   
cst = utc + (3600000*offset);
nd = new Date(cst); 
newdate = (nd.toLocaleString());

$('#q315 Input').val(newdate + ' CST');
});

 

0 0

Answer

SELECTED ANSWER
replied on August 20, 2017

Hi Terri,

Forms uses Moment Timezone library (https://momentjs.com/timezone/ ) and you could use it as well for converting timezone and handling the daylight saving logic. The script is like this:

newdate = moment().tz("US/Central").format("M/D/YYYY, h:mm:ss A");
1 0

Replies

replied on August 21, 2017

Thank you so much- that worked perfectly and reduced my lines of code substantially as well!!!  Thanks again,

Terri

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.