I am getting an exception while trying to get time zone for the location "America/Punta_Arenas". I am using joda LocalDateTime.
import org.joda.time.{DateTime, DateTimeZone}
val timezone = DateTimeZone.forID("America/Punta_Arenas")
So the above statement is throwing the following exception
java.lang.IllegalArgumentException: The datetime zone id 'America/Punta_Arenas' is not recognised
Is there any way I can get the time zone for the location America/Punta_Arenas? any help is appreciated.
Joda-Time carries its own copy of the time zone data known as tzdata. Time zone definitions change, so this file may need updating.
You haven't mentioned which version of Joda-Time you are using, first upgrade to latest if possible and that should work:
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.1</version>
</dependency>
The Joda-Time project is now in maintenance-mode. It’s creator, Stephen Colebourne, went on to lead JSR 310 and its implementation, java.time, found in Java 8 and later. This is the official successor to Joda-Time.
In Java's java.time
package you will find ZoneId.of.
ZoneId zoneId = ZoneId.of("America/Punta_Arenas");
Much of java.time functionality is back-ported to Java 6 & 7 in the ThreeTen-Backport project, another project led by Stephen Colebourne.
There you will find the org.threeten.bp.ZoneId
class.
<!-- https://mvnrepository.com/artifact/org.threeten/threetenbp -->
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.3.8</version>
</dependency>
The code will be the same as above with different import:
import org.threeten.bp.ZoneId;
ZoneId zoneId = ZoneId.of("America/Punta_Arenas");
Hope that helps