Pregunta

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

¿Fue útil?

Solución

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/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top