Format Date as “yyyy-MM-dd'T'HH:mm:ss.SSS'Z'”

后端 未结 5 630
囚心锁ツ
囚心锁ツ 2021-02-02 05:49

I need to format a date as yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\' as specified by Parse\'s REST API for Facebook. I was wondering what the most lightweight

5条回答
  •  不要未来只要你来
    2021-02-02 06:11

    toISOString() will return current UTC time only not the current local time. If you want to get the current local time in yyyy-MM-ddTHH:mm:ss.SSSZ format then you should get the current time using following two methods

    Method 1:

    document.write(new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString());

    Method 2:

    document.write(new Date(new Date().getTime() - new Date().getTimezoneOffset() * 60000).toISOString());

提交回复
热议问题