java時區轉換(GMT)

// fromTime 原始時區
 
// toTime 須要轉換到的時區
  
public static Date getGMTTime(Date retdate, String fromTime, String toTime){
   Calendar cal = Calendar.getInstance();
  cal.setTimeZone(TimeZone.getTimeZone(toTime));
  cal.setTime(retdate);
  Calendar date = Calendar.getInstance();
  date.setTimeZone(TimeZone.getTimeZone(fromTime));
  date.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND)); 
  date.set(cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH),cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND));
  return date.getTime();
 }
相關文章
相關標籤/搜索