admin管理员组

文章数量:1429841

I have an ISO-8601 date of the form:

2014-02-02T15:00:00-0800

Can anyone demonstrate how to to extract a time of the form

3:00pm

Using moment.js

I have an ISO-8601 date of the form:

2014-02-02T15:00:00-0800

Can anyone demonstrate how to to extract a time of the form

3:00pm

Using moment.js

Share Improve this question asked Jan 20, 2014 at 22:45 Ben PearceBen Pearce 7,10419 gold badges76 silver badges129 bronze badges 3
  • possible duplicate of Help parsing ISO 8601 date in Javascript – SOReader Commented Jan 20, 2014 at 22:49
  • There's no moment.js solution in the referenced question. – Ben Pearce Commented Jan 20, 2014 at 23:04
  • 1 have you checked the moment.js documentation? – jeremy Commented Jan 21, 2014 at 0:46
Add a ment  | 

1 Answer 1

Reset to default 3

Here you find Parse documentation. Here is Format. Combined together gives:

var dateAsString = '...';
moment.utc(dateAsString).format('h:mmA');

http://jsfiddle/76Ued/1/
http://jsfiddle/76Ued/2/ <- this one uses local()

EDIT
Version considering Matt Johnson's hint:

var dateAsString = '...';
moment(dateAsString).format('h:mmA');

http://jsfiddle/76Ued/13/

本文标签: javascriptParsing a human readable time from an ISO8601 formatted string using momentjsStack Overflow