android - 将时间转换为另一个时区
问题描述
我有一个简单的代码,我想将某个给定时间转换为另一个时区,在我的情况下,时间是英国本地时间,但如果用户居住在不同的国家,我需要将时间转换为另一个时区,我试过了这个简单的代码,但它对我不起作用,它给了我随机时间 04:00 任何帮助将不胜感激
- 这是代码
var localTime = "16:00" // simulating time to Uk timezone
localtime.text = localTime
timeZone.setOnClickListener {
val localTimes = "16:00"
val timeFormatter = SimpleDateFormat("hh:mm", Locale.UK)
val timezone = TimeZone.getDefault() // get device timezone
timeFormatter.timeZone = timezone
val timeToFormat = timeFormatter.parse(localTimes)
val formattedTime = timeFormatter.format(timeToFormat)
localtime.text = formattedTime
}
解决方案
推荐阅读
- ios - AVPlayerViewController 从全屏退出时从 UINavigationController 弹出所有 UIViewControllers (iOS 13)
- python - 详细视图和过期项目在 Django 中不起作用
- r - 多条线图,但我只想在一个特定的行中显示文本和点
- java - 如何在 Java 中重用图像并避免大量使用流?
- python - 我实施的 Bowyer-Watson Delaunay 三角剖分不会删除包含超三角形点的三角形
- android - 如何减少android工具栏中微调器文本和微调器箭头之间的空间
- excel - xlsxwriter - 通过引用来自另一个单元格的值创建超链接
- algorithm - 如何通过除法确定算法复杂度/增长顺序?
- react-native - 自定义打开/关闭抽屉动画
- python - 为什么'int'的类型是类型?