最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Parsing GMT date string with moment - Stack Overflow

programmeradmin3浏览0评论

I got the following input Wed, 08 Feb 2017 10:09:19 GMT form server. I've been trying to parse this string with momentjs but couldn't find format that will parse the GMT right.

and if i'm not putting format at all then i got warning value provided is not in a recognized ISO format. moment construction falls back to js Date()

Thanks!

I got the following input Wed, 08 Feb 2017 10:09:19 GMT form server. I've been trying to parse this string with momentjs but couldn't find format that will parse the GMT right.

and if i'm not putting format at all then i got warning value provided is not in a recognized ISO format. moment construction falls back to js Date()

Thanks!

Share Improve this question asked Feb 8, 2017 at 10:07 DimkinDimkin 7003 gold badges10 silver badges23 bronze badges 1
  • Check this stackoverflow./questions/32355297/… – kawadhiya21 Commented Feb 8, 2017 at 10:09
Add a ment  | 

1 Answer 1

Reset to default 6

Simply pass format paramter to moment constructor:

var m = moment('Wed, 08 Feb 2017 10:09:19 GMT', 'ddd, DD MMM YYYY HH:mm:ss'); // Parse string in local time
console.log(m.format());
var mUtc = moment.utc('Wed, 08 Feb 2017 10:09:19 GMT', 'ddd, DD MMM YYYY HH:mm:ss'); // Parse string in UTC time
console.log(mUtc.format());
<script src="https://cdnjs.cloudflare./ajax/libs/moment.js/2.17.1/moment.min.js"></script>

Note that by default moment parses and displays in local time, if you need UTC see moment.utc. If you need with multiple timezone use moment-timezone.

发布评论

评论列表(0)

  1. 暂无评论