Date and Time Zone

Date/Time Zone

Note: The latest version of the time zone database can be installed via the " timezonedb from PECL. Have a date/time field that pulls from an API that is not in my time zone. Any way to convert the time zone to CST? When you display the Activity Feed or Date fields in contact profiles, for example, they are displayed in relation to your computer's current time zone setting. You have two options for setting the date and time for the device.


Useful tip for brasilian programmers who need time zone information. AC' => 'America/Rio_branco', 'AL' => 'America/Maceio', 'AP' => 'America/Belem', 'AM' => 'America/Manaus', 'BA' => 'America/Bahia', 'CE' => 'America/Fortaleza', 'DF' => 'America/Sao_Paulo', ES' => 'America/Sao_Paulo', 'GO' => 'America/Sao_Paulo', 'MA' => 'America/Fortaleza', 'MT' => 'America/Cuiaba', 'MS' => 'America/Campo_Grande', 'MG' => 'America/Sao_Paulo', 'PR' => 'America/Sao_Paulo'",

PB' => 'America/Fortaleza', 'PA' => 'America/Belem', 'PE' => 'America/Recife', 'PI' => 'America/Fortaleza', 'RJ' => 'America/Sao_Paulo', 'RN' =>'America/Fortaleza', 'RS' => 'America/Sao_Paulo', RO' =>'America/Porto_Velho','RR' =>'America/Boa_Vista','SC' =>'America/Sao_Paulo','SE' =>'America/Maceio','SP' =>'America/Sao_Paulo','TO' =>'America/Araguaia', ); Mistaken Mirai Densetsu when he says that the time zone "America/Sao_Paulo" does not exists and should be modified to "America/Brasilia".

These lists are on the basis of the Time Zone Database administered by the IANA. In accordance with the conventions on names, the part of the name where the place is located uses the "most densely populated town in a given county to depict the whole time zone, with other towns being selectable if they are still known or lead to a less equivocal name".

When searching for the time zone hairywaii, you will find it in Pacific/Honolulu (not America/Honolulu). Hopefully this will help someone with similar problems I faced with my time zone settings for my localehost. In Brazil, it should be noted that the Brazil time zone is incorrectly referred to as "America/Sao_Paulo", although it should be "America/Brasilia". Sao Paulo's time zone does not exists because this town follows Brasilia's time zone (BRT or BRST).

Setting the time zone of a date in Java

This short step-by-step guide explains how to adjust the time zone of a date using Java 7, Java 8 and the Joda Time Language Libraries. A new Date-Time API for working with date and time was implemented in Java 8, largely using the Joda Time API. Java Date Time API's instance Class model a current point on the time line in yourtime.

First we get the actual instance from the system time and ZoneId for a time zone name: Instance knowUtc =; ZoneId seeSingapore = ZoneId.of("Asia/Singapore"); Lastly the ZoneId and Instance can be used to build a date-time item with time zone detail. ZoneDateTime defines a date-time with a time zone in the ISO-8601 calendaring system:

Adjusting the time zone in Java 7 is a little difficult. There is no time zone information in the date category (which is a time class). First we get the actual date of the last time and a TimeZone object:

Eventually we can build a meanwhileUtc calender with the time zone of our SingaporeSingapore and time: NowUtc: Kalender jetztAsiaSingapore = Calendar.getInstance(asiaSingapore); nowAsiaSingapore.setTime(nowUtc); It is advisable to use the Java 7 date-time-API in favour of Java 8 date-time-API or the Joda-Time-Bibliothek.

When Java 8 is not an optional feature, we can still get the same kind of results from Joda-Time, a de facto date time clock standards in the prior Java 8 universe. First we need to append the dependence on Joda-Time to pom.xml: In order to display an accurate point on the time line, we can use Instant from org.joda.time packet.

Internal the clas contains a bit of information, the moment in miliseconds from the Java era of 01.01.1970TTT00:00:00:00Z: Instant nowUtc=; We use DateDimeZone to display a time zone (for the given time zone ID): DatTimeZone singapore = DatTimeZone.forID("Asia/Singapore"); Now the currentUtc time is transformed into a DateTime item using the time zone information:

DateDate Time Now Asia Singapore = NowUtc.toDate Time (Asia Singapore); So the Joda Time API can be used to merge date and time zone information. We have found out in this paper how to adjust the time zone in Java with Java 7, 8 and Joda-Time API. Joda-Time is a Java application that uses Java 7. For more information about date-time supporting Java 8, visit our Java 8 date-time tutorial.

Auch interessant

Mehr zum Thema