如何在JodaTime中获取本地机器的TimeZone? [英] How to get the TimeZone of the local machine in JodaTime?

查看:127
本文介绍了如何在JodaTime中获取本地机器的TimeZone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测本地机器所在的时区?

How can I detect the timezone where a local machine is in?

我试过 DateTimeZone.getDefault()但如果机器在德国,这不会给我时区德国。

I tried DateTimeZone.getDefault() but that does not give me eg timezone "germany" if the machine is in germany.

有可能吗?

推荐答案

DateTimeZone.getDefault()将返回您的时区ID,如果您的主人是位于德国。

DateTimeZone.getDefault() will return you the ID of your Timezone which should be Berlin, if your Host is located in Germany.

在格式化程序中,您必须执行类似 formatter.withZone(DateTimeZone.getDefault())。parseDateTime(yourDateTime)以便在你的字符串中包含时区。

In the formatter you have to do something like formatter.withZone(DateTimeZone.getDefault()).parseDateTime(yourDateTime) in order to have the timezone in your String.

这篇关于如何在JodaTime中获取本地机器的TimeZone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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