How to convert datetime from user timezone to est in javascript

I have a web application with a dynamic javascript calendar that allows users to set events for data and time. I need to send notifications to users, so I need to convert the date and time zone that they entered into Eastern Standard Time so that my notifications are sent at the right time.

I would like to do this in javascript, so when the data time value gets into php, it is in the right format before being added to the database.

So, to summarize, I need to convert the time and time to javascript, which I get by taking user time data, as the full UTC date, in the time zone of my servers, which is EST - New York.

Any help or direction on this would be greatly appreciated. Thanks:)

+7
source share
2 answers

Pl check this script

function convertToServerTimeZone(){ //EST offset = -5.0 clientDate = new Date(); utc = clientDate.getTime() + (clientDate.getTimezoneOffset() * 60000); serverDate = new Date(utc + (3600000*offset)); alert (serverDate.toLocaleString()); } 
+15
source

I would draw an EST timeline offset on the page during its rendering (via PHP), and then capture the UTC time on the client and estimate it by the amount you pulled into. Otherwise, if your server ever moves time intervals at which your page will unexpectedly report the wrong time.

I just did this recently, and found that the easiest way to handle this is to actually use mySQL (I assume your DB is), and just let IT convert the time zone for you while you enter the print date. If you donโ€™t worry, itโ€™s too complicated, and you are trying to completely reduce the work that your db does, I would go this way, not the nasty thing about trying to do manual TZ to JS conversions.

0
source

All Articles