本文介绍了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将中部时间转换为当地时间
发布评论