获取特定时区的SimpleDateFormat [英] Getting SimpleDateFormat for specific timezone
问题描述
我很难显示特定时区的时间.我有一个像电视应用程序这样的电视指南,它可以从服务器获取Unix时代所有程序的开始时间,我希望显示的时间可以是在荷兰,无论该应用程序用户在哪里,无论它来自哪个android设备.经过一番研究,我认为它会像这样工作:
I am having a hard time displaying time for a specific timezone. I have a TV Guide like app that gets all start times of the programs in Unix epoch time from the server and I want the times to be shown in the time it would be in the Netherlands wherever the app user is and from whatever android device. After a bit of researching I would think it would work like this:
new SimpleDateFormat("HH:mm", new Locale("nl", "NL")).format(new Date(time*1000));
其中时间是一个纪元时间,例如1370497200
where time is a epoch time for example 1370497200
这是荷兰的07:40,但似乎只是您所使用设备的时区.在Samsung Galaxy Tab 2.0上进行了测试
This is 07:40 in the Netherlands but it seems it just takes the timezone of the device you are using. Tested it on a Samsung Galaxy Tab 2.0
我在做什么错了?
一个相关的问题: 根据 http://developer.android.com/reference/java/util/Locale .html 我不能假设nl_NL语言环境在所有设备上都可用,我将如何解决呢?
A related question: According to http://developer.android.com/reference/java/util/Locale.html I can't assume the nl_NL Locale is available on every device, how would I solve this?
旁注: http://www.epochconverter.com/是一种快速查看几点的好方法一定的纪元时间.
Sidenote: http://www.epochconverter.com/ is a nice way to quickly see what time a certain epoch time is.
推荐答案
使用
一个相关的问题:根据 http://developer.android.com/reference/java/util /Locale.html 我不能假设nl_NL语言环境在每台设备上都可用,我该如何解决呢? A related question: According to http://developer.android.com/reference/java/util/Locale.html I can't assume the nl_NL Locale is available on every device, how would I solve this? 您在这里谈论用户界面吗?如果是这样,那么您将无法解决.只有Google和/或OEM可以向系统添加新的语言环境. Are you talking about the UI here? If so, then you can not solve it. Only Google and/or OEMs can add new locales to the system. 这篇关于获取特定时区的SimpleDateFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!