admin管理员组

文章数量:1357646

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.

本文标签: javascriptParsing GMT date string with momentStack Overflow