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

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

问题描述

我在我的 Android 应用程序中使用 DatePicker 来显示用户可以选择的可用日期.我想在 GMT 时区显示日期,以便所有用户看到相同的日期.我还没有找到任何修改 DatePicker 时区的方法.我看到 DatePicker 使用默认时区选择时区.所以我将默认的 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()),并将其分配给设备的最小/最大日期属性日期选择器.

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 (Android) 中设置时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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