Domanda

How should I parse the following date with unknowns in momemnt.js? I want a year back but empty date and month?

Here is what I trying to do:

var temp = moment("UN-UNK-2010",'DD-MMM-YYYY');

È stato utile?

Soluzione

A moment object is a lightweight wrapper on a JavaScript Date, with a few extra properties. Neither can do what you are asking, because they both represent time as the number of milliseconds elapsed since Jan 1st 1970 UTC at midnight.

Your best bet is just to store the year as a number, instead of a moment or a Date.

Consider:

var s = 'UN-UNK-2010';
var year = +s.split('-')[2];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top