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');

有帮助吗?

解决方案

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];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top