전자 메일에서 여러 가지 가능한 형식으로 날짜를 추출한 다음 ISO 형식이 필요한 응용 프로그램에 전달하고 있습니다. 나는 moment.js를 사용하여 다양한 형식으로 날짜를 파싱 할 수 있다고 들었습니다.moment.js로 임의의 날짜/시간 구문 분석
Found: 1/22/2016
Milliseconds: 1453449600000
ISO: Fri Jan 22 2016 00:00:00 GMT-0800 (PST)
Found: Jan 22 2016
Milliseconds: 1453449600000
ISO: Fri Jan 22 2016 00:00:00 GMT-0800 (PST)
Found: 2016/1/22 03:00
Milliseconds: 1453460400000
ISO: Fri Jan 22 2016 03:00:00 GMT-0800 (PST)
이러한 모든 형식 및 기타 형식을 분석하는 데 시간을 어떻게 사용합니까?
var foundDue = taskNote.match(/(Deadline|Due):.*(\n|$)/ig);
// if we've found a deadline date...
if (foundDue) {
// Remove deadline/due tag
foundDue = foundDue[0].replace(/(Deadline|Due):? */i, "");
// Remove trailing and leading spaces
foundDue = foundDue.replace(/(^\s*|\s$)*/, "");
console.log("Found: "+ foundDue);
// Use a magic method to parse date
milliseconds = moment.??????(foundDue);
console.log("Milliseconds: "+ milliseconds);
console.log("Parsed2: "+ new Date(foundDue));
var taskDue = new Date(milliseconds);
console.log("ISO: "+ taskDue);
}
참고로이 질문은 earlier question에서 변경되었습니다.
'1/22/2016'의 예는 명확하지만 이메일의 날짜가 '1/2/2016'인 경우 어떻게됩니까? - 1 월 2 일인지 2 월 1 일인지 어떻게 알 수 있습니까? – nnnnnn