Android Convert Central Time to Local Time(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将中部时间转换为当地时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android将中部时间转换为当地时间
基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
