tl;dr
ZoneId.of( "Europe/Paris" )
.getRules()
.getOffset(
Instant.ofEpochMilli( 1_484_063_246L )
).getTotalSeconds()
Be careful about the word 'local'
In the Java date-time classes, the word local
as in LocalDate
, LocalTime
, and LocalDateTime
mean any locality, no specific locality. These classes purposely have no concept of time zone or offset. Definitely not what you want in the context of this Question.
Avoid legacy date-time classes
The Answer by Linuslabo is correct, and headed in the right direction using the java.time classes, but unnecessarily involves the old legacy java.util.Date
class.
Avoid the old legacy date-time classes (Date
, Calendar
, SimpleDateFormat
, etc.) as they have proven to be confusing, poorly designed, and troublesome. Now supplanted by the java.time classes.
Using java.time
The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction).
Your input seems to be a count of milliseconds since epoch.
Note that Java allows underscores in numeric literals for easier reading by humans.
Instant instant = Instant.ofEpochMilli( 1_484_063_246L );
You can adjust that into a time zone to see some region’s wall-clock time. Specify a proper time zone name in the format of continent/region
, such as America/Montreal
, Africa/Casablanca
, or Pacific/Auckland
. Never use the 3-4 letter abbreviation such as EST
or CET
or IST
as they are not true time zones, not standardized, and not even unique(!).
ZoneId zoneId = ZoneId.of( "Europe/Paris" );
ZonedDateTime zdt = instant.atZone( zoneId );
You can interrogate the ZoneId
for an offset-from-UTC (ZoneOffset
) via ZoneRules
, which seems to be the point of your Question. The offset will vary over time because of anomalies such as Daylight Saving Time (DST). A time zone is a collection of offsets for past, present, and near future. So when asking a zone for an offset, you must specify a moment in time.
ZoneOffset zoneOffset = zoneId.getRules().getOffset( instant );
You can get the offset amount as a total number of seconds, if desired.
int offsetInSeconds = zoneOffset.getTotalSeconds() ;
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8 and SE 9 and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.