In Java, dt.atOffset(offset) combines a LocalDateTime with a fixed ZoneOffset, such as +05:30 or Z for UTC. The result is an OffsetDateTime, which is a real moment on the timeline.
The local date and time stay exactly the same. Only the offset is added, so the moment is now known.
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file.
Syntax
Pass a ZoneOffset. Use ZoneOffset.UTC for UTC, or ZoneOffset.ofHoursMinutes() for others.
india instant: 2026-03-15T05:00:00Z
utc instant: 2026-03-15T10:30:00Z
same moment: false
same local: true
How It Works
An Instant is always in UTC. It shows the real moment, with the letter Z at the end.
India is earlier. 10:30 at +05:30 is 05:00 in UTC.
Different moments.isEqual on the OffsetDateTime values prints false.
Equal local parts. The date-time without the offset is the same, so the last line prints true.
Frequently Asked Questions
If the local time is already in UTC, use dt.atOffset(ZoneOffset.UTC). If it is in another zone, use dt.atZone(zone).withZoneSameInstant(ZoneOffset.UTC).
atOffset() uses a fixed offset such as +05:30. atZone() uses a region such as Asia/Kolkata, which knows daylight saving time changes.
Use dt.toEpochSecond(ZoneOffset.UTC), or dt.atOffset(offset).toEpochSecond().
No. The local date and time stay the same. Only the offset is added.
Use ZoneOffset.UTC, ZoneOffset.ofHours(2), ZoneOffset.ofHoursMinutes(5, 30), or ZoneOffset.of("+05:30").