2016-08-13 6 views
0

날짜를 문자열로 변환하면 날짜가 바뀝니다. 내 잘못은 뭐니?문자열에 자바 스크립트 날짜 형식 문제가 발생했습니다.

Date 2016-10-31T22:00:00.000Z 

을 내가 문자열로 변환 할 때 내가 얻을 :

날짜 나 반환

Thu Dec 01 2016 00:00:00 GMT+0200 

내 코드 : 당신은 UTC 시간 후있어

date = new Date("2016 11 31"); 
StringDate = date.toString(); 
console.log(StringDate); 
console.log(date); 

답변

1

, 어떤 Date.toUTCString()으로 인쇄 할 수 있습니다.

var date = new Date("2016 11 31"); 
var stringDate = date.toUTCString(); // See this line 
console.log(stringDate); 
console.log(date); 
0

사실 입력 내용이 잘못되었습니다. 2016-11-31과 같은 날짜가 없습니다. 그것은 12 월을 보여줍니다 그게 왜 01 2016

이 시도 :

date=new Date("2016 10 31"); //november consist 30 days only 
StringDate=date.toString(); 
console.log(StringDate); 
console.log(date); 
관련 문제