2013-03-01 3 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 объектов.

Смежные вопросы