Question

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

Was it helpful?

Solution

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

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

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

EDIT
Version considering Matt Johnson's hint:

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

http://jsfiddle.net/76Ued/13/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top