Convert facebook date to local timezone

Facebook returns this date

2010-12-16T14:39:30+0000 

However, I noticed that it was 5 hours ahead of my local time. It should be:

 2010-12-16T09:39:30+0000 

How can I convert this to local time in javascript?

Edit

After looking at some of the answers, I feel I have to determine what I'm looking for more clearly. How can I determine the user's local time zone for date formatting?

+4
source share
3 answers

Here is the function to handle ISO8601 dates in Javascript, it also handles the time offset correctly: http://delete.me.uk/2005/03/iso8601.html

+4
source

This may help you:

taken from Convert local time to another time zone using this JavaScript

 // function to calculate local time // in a different city // given the city UTC offset function calcTime(city, offset) { // create Date object for current location d = new Date(); // convert to msec // add local time zone offset // get UTC time in msec utc = d.getTime() + (d.getTimezoneOffset() * 60000); // create new Date object for different city // using supplied offset nd = new Date(utc + (3600000*offset)); // return time as a string return "The local time in " + city + " is " + nd.toLocaleString(); } // get Bombay time alert(calcTime('Bombay', '+5.5')); // get Singapore time alert(calcTime('Singapore', '+8')); // get London time alert(calcTime('London', '+1')); 
+4
source

This is how I did it in Javascript

 function timeStuff(time) { var date = new Date(time); date.setHours(date.getHours() - (date1.getTimezoneOffset()/60)); //for the timezone diff return date; } 
0
source

Source: https://habr.com/ru/post/1332358/


All Articles