Android的转换中部时间到当地时间当地时间、时间、Android

2023-09-06 01:16:54 作者:I 'm okay

我有一个存储时间戳为每个记录我插入一个MySQL数据库。我拉进我的Andr​​oid应用程序作为一个字符串时间戳。我的数据库位于具有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;
}

是否有意义?

does it make sense?