Android将中部时间转换为当地时间

编程入门 行业动态 更新时间:2024-10-28 19:27:52
本文介绍了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将中部时间转换为当地时间

本文发布于:2023-10-17 13:29:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1501068.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   当地时间   时间   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!