skip to Main Content

Hello I am using Twitter REST API to call the home_timeline for timelines.

But I found that the object it returned had the created_at with GMT+0 timezone, how can I adjust the timezone to the user’s local timezone for example GMT+8?

Here is the original data with GMT+0 from Twitter API:

Wed May 04 16:23:13 +0000 2016

2

Answers


  1. what’s the expected output format?

    you can try:

    var d = new Date('Wed May 04 16:23:13 +0000 2016');
    var localeTime = d.toLocaleString();
    console.log(localeTime);
    

    if you expect a specific output format, you can use http://momentjs.com/timezone/ , to change both the timezone and format

    Login or Signup to reply.
  2. I’m highly recommend to use MomentJS timezone library.

    Furthermore, I’m recommend not to use GMT+8 label for time shifting, and use, for example, “Asia/Shanghai” instead. I would save hours to debug for you.

    So, code barebone look like:

    let moment = require("moment-timezone");
    moment("Wed May 04 16:23:13 +0000 2016").tz("Asia/Shanghai").format('YYYYMMDD hh:mm:ss')
    

    Output would be something like "20160505 12:23:13".

    Thanks!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search