2014-12-02 3 views
-1

Firefox (V34 최신)에서 이것이 작동하지 않는 이유를 말씀해 주시겠습니까? 그것은 다른 모든 브라우저에서 잘 작동합니다. 'DatePosted'가 잘못된 날짜로 표시됩니다. 왜요? 어떤 도움을 주시면 감사하겠습니다. 새로운 날짜가 Firefox에서 작동하지 않습니다.

//Get local time for everything: 
     data.Comments.forEach(function (x) { 
     x.DatePosted = new Date(x.DatePosted.toString().replace("T", " ") + " UTC"); 
     }); 

enter image description here

참고 : x.DatePosted : "2014-11-18T08 : 06 : 39.06"당신은 그나마

+0

[JQuery와 날짜 변환 크롬 작동하지만 IE와 파이어 폭스는하지 (의 중복 가능성 http://stackoverflow.com/questions/9595902/ jquery-date-conversion-chrome-works-but-ie-and-firefox-dont) 또는 http://stackoverflow.com/questions/2182246/javascript-dates-in-ie-nan-firefox-chrome-ok – CBroe

+3

Can 당신은'x.DatePosted.toString()'의 값을 게시 하시겠습니까? –

+0

@RahulDesai "2014-11-18T08 : 06 : 39.06" – Sampath

답변

2

T를 교체해야합니다. 그것 없이도 작동합니다 (Chrome 및 Firefox에서 테스트 됨).

Date 개체를 설정 한 후 UTC로 가져옵니다.

아래 니펫을 사용 :

var myDate = new Date("2014-11-18T08:06:39.06"); 
 

 
// now set it to UTC 
 
var myDateinUTC = Date.UTC(myDate.getFullYear(), myDate.getMonth(), myDate.getDate(), myDate.getHours(), myDate.getMinutes(), myDate.getSeconds(), myDate.getMilliseconds()); 
 

 
console.dir(myDateinUTC); 
 

 
var myNewDate = new Date(myDateinUTC); 
 

 
console.log(myNewDate.getMonth()); // just to test

+0

예. 부품을 교체하지 않고 사용한 적이 있으며 지금은 작동 중입니다. 많이 감사합니다 :) – Sampath

관련 문제