Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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"));        
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

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());

will print GMT -03:00 for America/Sao_Paulo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...