2013-03-01 5 views
1

여기에 제 코드가 있지만 타임 존을 변경 한 후에 동일한 타임 스탬프가 표시됩니다.타임 스탬프를 다른 gmt + 타임 스탬프로 변경하십시오.

TimeZone timeZone = TimeZone.getTimeZone("GMT+11"); 
Calendar cal1 = Calendar.getInstance(); 
Calendar cal2 = Calendar.getInstance(); 

cal1.setTimeInMillis(Long.parseLong(classListDto.get(i) 
    .getClassStartTime()) * THOUSAND); 
cal2.setTimeInMillis(Long.parseLong(classListDto.get(i) 
    .getClassEndTime()) * THOUSAND); 
cal1.setTimeZone(timeZone); 
cal2.setTimeZone(timeZone); 

long startTimestamp = cal1.getTimeInMillis(); 
long endTimestamp = cal2.getTimeInMillis(); 

답변

1

Calendar 인스턴스에서 시간대를 설정하는 대신 다음과 같이 시도해보십시오.

TimeZone timeZone = TimeZone.getTimeZone("GMT+11"); 
Calendar cal1 = Calendar.getInstance(); 
cal1.setTimeInMillis(Long.parseLong(classListDto.get(i).getClassStartTime()) * THOUSAND); 

Date tempDate = cal1.getTime(); 
SimpleDateFormat df = new SimpleDateFormat(); 
SimpleDateFormat df1 = new SimpleDateFormat(); 

df.setTimeZone(timeZone); 
Date gmtDate = df1.parse(df.format(tempDate)); // Put this in a Try/Catch block 

long startTimestamp = gmtDate.getTime(); 

희망이 있습니다. 나는 2 SimpleDateFormat 개체를 사용하는 그 엉터리를 알고있다.

관련 문제