打印服务器的时区 [英] Print timezone of server
本文介绍了打印服务器的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要显示服务器的时区,例如GMT-03:00,我如何在Java中使用?
I need show the timezone of server, example GMT-03:00, how I can make this in Java?
public static void main(String[] args) {
logger.error(Calendar.getInstance().getTimeZone().getTimeZone("America/Sao_Paulo"));
}
推荐答案
我推荐 -Time 库,用于与Java一起工作。这比默认实现要好得多。
I recommend Joda-Time library for work with time in Java. It's much better than default realization.
DateTimeZone zone = DateTimeZone.forTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("ZZ");
System.out.println("GMT "+dateTimeFormatter.withZone(zone).print(0) +" for "+zone.toString());
将为美国/ Sao_Paulo打印 GMT -03:00
will print GMT -03:00 for America/Sao_Paulo
这篇关于打印服务器的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文