本文介紹了Android將中部時間轉換為當地時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個 MySql 數據庫,它為我插入的每條記錄存儲一個時間戳.我將該時間戳作為字符串提取到我的 Android 應用程序中.我的數據庫位于具有 CST 時區的服務器上.我想將該 CST 時間戳轉換為 Android 設備的本地時間.
I have a MySql database that stores a timestamp for each record I insert. I pull that timestamp into my Android application as a string. My database is located on a server that has a TimeZone of CST. I want to convert that CST timestamp to the Android device's local time.
有人可以幫忙嗎?
推薦答案
你不能簡單地用 simpleDateFormat?然后你只需定義傳入日期的結構(df)并將其轉換為你想要的形式(df):
can't you simply convert the date with simpleDateFormat? then you just define the structure of your incoming date like that (df) and transform it to the form you want (df):
private static DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
private static DateFormat df2 = new SimpleDateFormat("dd/MM/yyyy 'at' HH:mm");
public void setyourDate(String yourDate) {
Date date2;
yourDate = getyourDate() + "" + yourDate;
try {
date2 = df.parse(yourDate);
yourDate = df2.format(date2);
} catch (ParseException e) {
}
this.yourDate = yourDate;
}
有意義嗎?
這篇關于Android將中部時間轉換為當地時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!