在DatePicker中设置TimeZone(Android) [英] Setting TimeZone in DatePicker (Android)

查看:92
本文介绍了在DatePicker中设置TimeZone(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android应用程序中使用DatePicker来显示用户可以选择的可用日期。我想在GMT时区中显示日期,以便所有用户看到相同的日期。我还没有找到修改DatePicker的时区的任何方法。我看到DatePicker通过使用默认的TimeZone选择了TimeZone。因此,我将默认的TimeZone更改为GMT,并且可以使用,但是现在整体TimeZone已更改,因此不是最佳解决方案。有人对更好的东西有任何想法吗?谢谢

I'm using DatePicker in my Android Application to display available dates that the user can pick. I want to display the dates in the GMT Time Zone so that all users see the same dates. I haven't found any way of modifying the TimeZone of the DatePicker. I saw that DatePicker picks the TimeZone by using the default TimeZone. So I changed the default TimeZone to GMT and it worked but now the overall TimeZone has changed so not the best solution. Anyone have any ideas on something better? Thank you

推荐答案

您使用长原语指定setMinDate和setMaxDate。在分配过程中无法包含特定的时区。该方法将始终使用设备的区域设置。 它在文档中

You specify setMinDate and setMaxDate with a long primitive. There is no way to include a specific timezone during the assignment. The method will always use the devices locale settings. It's in the documentation.

您必须首先创建要使用的最小和最大日期,然后调整设备的本地时区,然后使用它们各自的长整数(getTimeInMillis()) ,并将其分配给DatePicker的最小/最大日期属性。

You have to first create the min and max dates you want to use then adjust for the local timezone of your device and then use their respective long's, (getTimeInMillis()), and assign it to min/max date properties of the DatePicker.

这篇关于在DatePicker中设置TimeZone(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆