0
timestamp를 함수 아래로 전달하고 올바르게 날짜 문자열을 반환하지만 아래 행을 실행하면 잘못된 날짜가 잘못 표시됩니다.새로운 날짜()를 사용하는 잘못된 날짜 문제
var postDate = new Date(this.ConvertServerDateToLocal(timestamp));
//postDate returns invalid date object.
ConvertServerDateToLocal: function(dateInput){
// EST - UTC offset: 4 hours
var offset = 4.0,
/*
- calculate the difference between the server EST date and UTC
- the value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00 UTC.
- the time-zone offset is the difference, in minutes, between UTC and local time
- 60000 milliseconds = 60 seconds = 1 minute
*/
serverDate = new Date(dateInput),
utc = serverDate.getTime() - (serverDate.getTimezoneOffset() * 60000),
/*
- apply the offset between UTC and EST (4 hours)
- 3600000 milliseconds = 3600 seconds = 60 minutes = 1 hour
*/
clientDate = new Date(utc + (3600000 * offset));
return clientDate.toLocaleString();
}
다음은 ConvertServerDateToLocal() 함수에 전달하는 타임 스탬프의 예입니다.
타임 스탬프 = "2017년 11월 22일 23시 5분 58초"// // = "2017년 11월 9일 18시 30분 19초"출력 후
타임 스탬프를 유효하지 않은 날짜를 던지는 제대로