javascript - Convert facebook date to local time zone - Stack Overflow

Facebook returns this date 2010-12-16T14:39:30+0000However, I noticed that it's 5 hours ahead of m

Facebook returns this date

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

However, I noticed that it's 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 seeing some responses, I feel I should define what I'm searching for more clearly. How would I be able to determine the user's local time zone to format the date?

Facebook returns this date

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

However, I noticed that it's 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 seeing some responses, I feel I should define what I'm searching for more clearly. How would I be able to determine the user's local time zone to format the date?

Share Improve this question edited Dec 16, 2010 at 15:07 asked Dec 16, 2010 at 14:57 user356808user356808 1
  • The '+0000' is the time zone. If you're on PST that part would be '-0500'. – Rup Commented Dec 16, 2010 at 14:59
Add a ment  | 

3 Answers 3

Reset to default 4

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

This might help you:

taken from Convert the local time to another time zone with this JavaScript

// function to calculate local time
// in a different city
// given the city's 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'));

Here's 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;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742324602a4422493.html

相关推荐

  • javascript - Convert facebook date to local time zone - Stack Overflow

    Facebook returns this date 2010-12-16T14:39:30+0000However, I noticed that it's 5 hours ahead of m

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信