TL; dr
ZoneId.of( "America/Montreal" )
java.time
Here is the modern java.time (see Tutorial ) version of the correct mamboking answer .
Code example:
ZonedDateTime now = ZonedDateTime.now( ZoneId.of( "America/Montreal" ) ); β¦ ZoneId z = now.getZone(); ZoneRules zoneRules = z.getRules(); Boolean isDst = zoneRules.isDaylightSavings( now.toInstant() );
Notice that on the last line, we had to extract the Instant object from our ZonedDateTime object with a simple call toInstant .
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old obsolete date and time classes, such as java.util.Date , Calendar , and SimpleDateFormat .
The Joda-Time project, currently in maintenance mode , recommends switching to the java.time classes.
To learn more, see the Oracle Tutorial . And a search for many examples and explanations. JSR 310 specification .
You can exchange java.time objects directly with your database. Use a JDBC driver that conforms to JDBC 4.2 or later. No strings needed, no java.sql.* Needed.
Where to get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a testing ground for possible future additions to java.time. Here you can find some useful classes such as Interval , YearWeek , YearQuarter and others .
Basil Bourque Sep 11 '15 at 16:47 2015-09-11 16:47
source share