From comment of variable offset:

The offset is the first index of the storage that is used.

Internally a String is represented as a sequence of chars in an array.

This is the first char to use from the array.

It has been introducted because some operations like substring create a new String using the original char array using a different offset.

So basically is a variable introduced for a performance tuning for substring operations.

Note: the offset variable is always with the variable private final int count;

Answer from Davide Lorenzo MARINO on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › OffsetTime.html
OffsetTime (Java Platform SE 8 )
3 weeks ago - A time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00.
🌐
Baeldung
baeldung.com › home › java › java dates › zoneoffset in java
ZoneOffset in Java | Baeldung
November 19, 2025 - ZoneOffset extends ZoneId and defines the fixed offset of the current time-zone with GMT/UTC, such as +02:00.
🌐
TutorialsPoint
tutorialspoint.com › javatime › javatime_instant_atoffset.htm
java.time.Instant.atOffset() Method Example
package com.tutorialspoint; import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; public class InstantDemo { public static void main(String[] args) { Instant instant = Instant.parse("2017-02-03T10:37:30.00Z"); System.out.println(instant); ZoneOffset offset = ZoneOffset.ofHours(5); OffsetDateTime date = instant.atOffset(offset); System.out.println(date); } }
🌐
Dev.java
dev.java › learn › date-time › zoneid-zone-offset
Time Zone and Offset - Dev.java
January 27, 2022 - Although all three classes maintain an offset from Greenwich/UTC time, only ZonedDateTime uses the ZoneRules, part of the java.time.zone package, to determine how an offset varies for a particular time zone.
🌐
Quora
quora.com › What-does-offset-mean-in-Java
What does offset mean in Java? - Quora
Answer: In JDBC we use start and offset. Start is the starting index or the starting row number you want to fetch from a table in database and offset is the number of rows you want.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › OffsetDateTime.html
OffsetDateTime (Java Platform SE 8 )
3 weeks ago - OffsetDateTime is an immutable representation of a date-time with an offset. This class stores all date and time fields, to a precision of nanoseconds, as well as the offset from UTC/Greenwich.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-8-clock-offset-method-with-examples
Java 8 Clock offset() method with Examples - GeeksforGeeks
December 10, 2018 - The Java Date Time API was added from Java version 8. The offset() method is a static method of Clock class which returns a clock with instant equal to the sum of the instants of clock passed as parameter and specific Offset duration.
🌐
DEV Community
dev.to › sadiul_hakim › time-zones-and-offsets-in-java-2d8m
Time Zones and Offsets in Java - DEV Community
September 19, 2025 - An offset, on the other hand, is a fixed duration of time, like $+05:30$ or $-08:00$, that a specific location's time is ahead of or behind Coordinated Universal Time (UTC). Unlike a time zone, an offset does not contain any historical or daylight ...
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › javatime › javatime_clock_offset.htm
java.time.Clock.offset() Method Example
The java.time.Clock.offset() method obtains a clock that returns instants from the specified clock with the specified duration added.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › time › OffsetTime.html
OffsetTime (Java SE 17 & JDK 17)
January 20, 2026 - OffsetTime is an immutable date-time object that represents a time, often viewed as hour-minute-second-offset. This class stores all time fields, to a precision of nanoseconds, as well as a zone offset.
🌐
Dariawan
dariawan.com › tutorials › java › java-offsetdatetime-tutorial-examples
Java OffsetDateTime Tutorial with Examples | Dariawan
August 31, 2019 - Java → · OffsetDateTime class represent a date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 1980-04-09T10:15:30+07:00. This class is immutable and thread-safe.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › ZoneOffset.html
ZoneOffset (Java Platform SE 8 )
3 weeks ago - Java™ Platform Standard Ed. 8 ... public final class ZoneOffset extends ZoneId implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable · A time-zone offset from Greenwich/UTC, such as +02:00.
🌐
TutorialsPoint
tutorialspoint.com › javatime › javatime_offsettime.htm
java.time.OffsetTime Class
The java.time.OffsetTime class represents a time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00.
🌐
W3Schools
w3schools.com › java › ref_string_offsetbycodepoints.asp
Java String offsetByCodePoints() Method
Java Examples Java Compiler Java Exercises Java Quiz Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate · ❮ String Methods · Get an index from a string which is offset from another index by a number of code points: String myStr = "Hello, World!"; int result = myStr.offsetByCodePoints(3, 2); System.out.println(result); Try it Yourself » ·
Top answer
1 of 2
4

You can use SimpleDateFormat's setTimeZone method as below:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

public class DateFormatExample {

    private static SimpleDateFormat offsetDateFormat = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ssZ");

    private static SimpleDateFormat dateFormatter = new SimpleDateFormat(
            "ddMMMyyyyHHmm");

    public static void main(String[] args) throws ParseException {
        String date = "15Sep20162040";
        String result = offsetDateFormat.format(dateFormatter.parse(date));
        System.out.println(result); // 2016-09-15T20:40:00+0400
        offsetDateFormat.setTimeZone(TimeZone.getTimeZone("GMT-8:00"));
        result = offsetDateFormat.format(dateFormatter.parse(date));
        System.out.println(result);
    }
}

If you simply want to change the timezone at the end of result, please try the following:

    String offset = "GMT-8:00";
    String date = "15Sep20162040";
    date = date+" "+offset;
    SimpleDateFormat dateFormatter2 = new SimpleDateFormat("ddMMMyyyyHHmm Z");
    SimpleDateFormat offsetDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    offsetDateFormat2.setTimeZone(TimeZone.getTimeZone(offset));
    String result = offsetDateFormat2.format(dateFormatter2.parse(date));
    System.out.println(result);

Hope this helps.

2 of 2
2

tl;dr

ZonedDateTime zdt = 
    LocalDateTime.parse ( "15Sep20162040" , 
                          DateTimeFormatter.ofPattern ( "ddMMMyyyyHHmm" )
                                           .withLocale( Locale.English ) 
                        )
                 .atZone ( ZoneId.of ( "America/Puerto_Rico" ) );

2016-09-15T20:40-04:00[America/Puerto_Rico]

zdt.atZone( ZoneId.of ( "Pacific/Auckland" ) )  // Same moment viewed through different wall-clock time

2016-09-16T12:40+12:00[Pacific/Auckland]

Using java.time

Avoid the troublesome old date-time classes, now supplanted by the java.time classes.

Define a formatting pattern to match your input string.

String input = "15Sep20162040";
DateTimeFormatter f = DateTimeFormatter.ofPattern ( "ddMMMyyyyHHmm" ).withLocale ( Locale.ENGLISH );

By the way, this is a terrible format for a date-time string. It assumes English, abuses English with incorrect abbreviation of month name, and is confusing and ambiguous. Instead, use the standard ISO 8601 formats when serializing date-time values to text.

Un-zoned

Parse the input string as a LocalDateTime since it lacks any info about offset-from-UTC or time zone.

LocalDateTime ldt = LocalDateTime.parse ( input , f );

Understand that without an offset or time zone, this LocalDateTime object has no real meaning. It represents many possible moments, but not a specific point on the timeline. For example, noon in Auckland NZ is a different moment than noon in Kolkata India which is an earlier moment than noon in Paris France.

Assign an offset-from-UTC

You indicate this date-time was intended to be a moment with an offset-from-UTC of four hours behind UTC (-04:00). So next we apply a ZoneOffset to get a OffsetDateTime object.

Tip: Always include the colon and the minutes and padding zeros in your offset-from-UTC strings. While not required by the ISO 8601 standard, common software libraries and protocols expect the fuller formatting.

ZoneOffset offset = ZoneOffset.ofHours( -4 ); 
OffsetDateTime odt = ldt.atOffset( offset );

Assign a time zone

If by your context you knew of a time zone rather than a mere offset, use a ZoneId to instantiate a ZonedDateTime object. A time zone is an offset plus a set of rules for handling anomalies such as Daylight Saving Time (DST).

Specify a proper time zone name in the format of continent/region. Never use the 3-4 letter abbreviation such as EST or IST as they are not true time zones, not standardized, and not even unique(!).

ZoneId z = ZoneId.of( "America/Puerto_Rico" );
ZonedDateTime zdt = ldt.atZone( z );

Different time zones

Your question is not clear near the end, about changing offsets. If your goal is to view the date-time through the various lenses of various time zones, you can easily adjust by creating new ZonedDateTime objects. Assign a different time zone to each.

Note that all these date-time objects (zdt, zKolkata, and zAuckland) represent the same moment, the same point on the timeline. Each presents a different wall-clock time but for the same simultaneous moment.

ZoneId zKolkata = ZoneId.of ( "Asia/Kolkata" );
ZonedDateTime zdtKolkata = zdt.withZoneSameInstant ( zKolkata );

ZoneId zAuckland = ZoneId.of ( "Pacific/Auckland" );
ZonedDateTime zdtAuckland = zdt.withZoneSameInstant ( zAuckland );

System.out.println ( "input: " + input + " | ldt: " + ldt + " | odt: " + odt + " | zdt: " + zdt + " | zdtKolkata " + zdtKolkata + " | zdtAuckland: " + zdtAuckland );

Dump to console.

input: 15Sep20162040 | ldt: 2016-09-15T20:40 | odt: 2016-09-15T20:40-04:00 | zdt: 2016-09-15T20:40-04:00[America/Puerto_Rico] | zdtKolkata 2016-09-16T06:10+05:30[Asia/Kolkata] | zdtAuckland: 2016-09-16T12:40+12:00[Pacific/Auckland]

About java.time

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old date-time classes such as java.util.Date, .Calendar, & java.text.SimpleDateFormat.

The Joda-Time project, now in maintenance mode, advises migration to java.time.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations.

Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP (see How to use…).

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.

🌐
BeginnersBook
beginnersbook.com › 2022 › 06 › java-offsettime-class-explained-with-examples
Java OffsetTime Class explained with examples
September 11, 2022 - Java OffsetTime class represents time with an offset from UTC timezone such as 11:23:45+02:00. The time represented by an instance of this class is often viewed as hour-minute-second-offset, however this class can store time upto the precision of nanoseconds.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-time-offsettime-class-in-java
java.time.OffsetTime Class in Java - GeeksforGeeks
January 17, 2022 - Java OffsetTime class is an immutable date-time object that represents a time, often viewed as hour-minute-second offset. OffsetTime class represents a time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 18:30:45+08:00, ...
🌐
OpenJDK
cr.openjdk.org › ~sherman › threeten › pirateplus › javax › time › OffsetDate.html
OffsetDate (ThreeTen date and time API)
public static OffsetDate parse(java.lang.String text, CalendricalFormatter formatter) Obtains an instance of OffsetDate from a text string using a specific formatter. The text is parsed using the formatter, returning a date. Parameters: text - the text to parse, not null ·
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › › › java.base › java › time › OffsetDateTime.html
OffsetDateTime (Java SE 11 & JDK 11 )
October 20, 2025 - A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00.