문제

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