2010-08-16 2 views
0

나는 사람이 읽을 수있는 날짜 문자열로 타임 스탬프를 파싱하려고하지만, 나는 1970 년 1 월 15 일을 반환으로 유지하고있다. JAVA/GWT - 1970 년 1 월 15 일로 되 돌리는 DateFormat

//Here is my formatter 
DateTimeFormat Format = DateTimeFormat.getFormat("MM/dd/yyyy"); 

//Here is my timestamp - SHOULD BE AUGUST 16TH, 2010 
String date = "1281966439"; 

//Here is where I create the date, and format it 
int intDate = Integer.parseInt(date); 
Date eventDate = new Date(intDate); 
String eventDateFinal = Format.format(eventDate); 

//In this alert, I get 1/15/1970 
Window.alert(eventFinal); 

은 내가 대신 초 (밀리 초)을 사용하고있을 수 있습니다 생각하지만 난 그것을 밀리 초 단위로 값을 공급하면, 나는 예외를 얻을.

누구든지이 문제가 있습니까?

답변

2

Date 생성자는 int가 아닌 long을 사용하며이 시간 이후의 밀리 초입니다.

//Here is my formatter 
DateTimeFormat Format = DateTimeFormat.getFormat("MM/dd/yyyy"); 

//Here is my timestamp - SHOULD BE AUGUST 16TH, 2010 
String date = "1281966439000"; 

//Here is where I create the date, and format it 
long longDate = Long.parseLong(date); 
Date eventDate = new Date(longDate); 
String eventDateFinal = Format.format(eventDate); 

//In this alert, I get 1/15/1970 
Window.alert(eventFinal); 
+0

올바른 코드를 포함하여 두 분 모두 맞았습니다. – tpow

관련 문제