2013-07-01 72 views
0

您好我得到了Web服務的結果2013年6月26日從格林尼治標準時間12:00:00 AM如何使轉換爲本地設備time.Please給我的解決方案GMT轉換本地設備的日期和時間日期時間?

我實現這個代碼,但沒有工作

public static String DateTime(Date date) { 
    SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy hh:mm a"); 
    return dateformat.format(date); 
} 

回答

3

在解析日期之前設置格式化程序的時區。

public static String DateTime(Date date) { 
    SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy hh:mm a"); 
    TimeZone tz = TimeZone.getDefault(); //Will return your device current time zone 
    dateformat.setTimeZone(tz); //Set the time zone to your simple date formatter 
    return dateformat.format(date); 
}  
相關問題