TL; dr
Instant.ofEpochMilli( 1_317_816_735_000L ) .atZone( ZoneId.of( "Pacific/Auckland" ) ) .format( DateTimeFormatter.ofLocalizedDateTime( FormatStyle.MEDIUM ).withLocale( new Locale( "en" , "NZ" ) ) )
…also…
LocalDateTime.parse( "2011-10-06 03:35:05".replace( " " , "T" ) ) .atZone( ZoneId.of( "Pacific/Auckland" ) )
java.time
The Question and most Answers use legacy date and time classes from the earliest versions of Java. These old classes were unpleasant and confusing. Avoid them. Use java.time classes instead.
ISO 8601
Your input string is almost in the standard ISO 8601 format. Just replace the SPACE in the middle with the letter T
String input = "2011-10-06 03:35:05".replace( " " , "T" );
LocalDateTime
Now analyze as LocalDateTime because there is no input information about the offset from UTC or time zone. LocalDateTime has no notion of offset or time zone, so it does not represent the actual moment in the timeline.
LocalDateTime ldt = LocalDateTime.parse( input );
ZoneOffset
You seem to be saying that from the business context, you know that this line is intended to represent a moment that is 13 hours ahead of UTC. So we create an instance of ZoneOffset .
ZoneOffset offset = ZoneOffset.ofHours( 13 ); // 13 hours ahead of UTC, in the far east of the globe.
OffsetDateTime
Apply it to get an OffsetDateTime object. This is becoming a moment in time.
OffsetDateTime odt = ldt.atOffset( offset);
ZoneId
But then you mention New Zealand. So you meant a specific time zone. The time zone is an offset from UTC plus a set of rules for handling anomalies such as Daylight Saving Time (DST). So we can specify the ZoneId for the ZonedDateTime and not just the offset.
Please enter a valid time zone name . Never use a 3-4-letter abbreviation, such as EST or IST as they are not true time zones, are not standardized, and are not even unique (!). For example, Pacific/Auckland .
ZoneId z = ZoneId.of( "Pacific/Auckland" );
ZonedDateTime
Apply ZoneId .
ZonedDateTime zdt = ldt.atZone( z );
You can easily switch to another zone at the same time on the timeline.
ZoneId zParis = ZoneId.of( "Europe/Paris" ); ZonedDateTime zdtParis = zdt.withZoneSameInstant( zParis ); // Same moment in time, but seen through lens of Paris wall-clock time.
Count from era
I highly recommend that you do not process date and time values as a reference from an era, for example, milliseconds since the beginning of 1970 UTC. But if necessary, create Instant from such a number.
Instant instant = Instant.ofEpochMilli( 1_317_816_735_000L );
Then set the time zone as shown above if you want to move away from UTC.
ZoneId z = ZoneId.of( "Pacific/Auckland" ); ZonedDateTime zdt = instant.atZone( z );
Your value is 1_317_816_735_000L :
2011-10-05T12:12:15Z (Wednesday, October 05, 2011 12:12:15 GMT)2011-10-06T01:12:15+13:00[Pacific/Auckland] (Thursday, October 6, 2011 01:12:15 in Auckland, New Zealand).
Generate lines
To generate a string in the standard ISO 8601 format , simply call toString . Note that ZonedDateTime intelligently extends the standard format by adding the time zone name in square brackets.
String output = zdt.toString();
For other formats, search for the DateTimeFormatter class. Already covered many times.
Specify FormatStyle and Locale .
Locale l = new Locale( "en" , "NZ" ); DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.MEDIUM ).withLocale( l ); String output = zdt.format( f );
Note that the time zone has nothing to do with the locale. You can display the date / time in Europe/Paris in Japanese and the cultural norms, or the date in Asia/Kolkata in the Portuguese language and the cultural norms of Brazil.
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old date and time classes, such as java.util.Date , .Calendar , and java.text.SimpleDateFormat .
The Joda-Time project, currently in maintenance mode , recommends switching to java.time.
To learn more, see the Oracle Tutorial . And a search for many examples and explanations.
Most of the functionality of java.time has been ported to Java 6 and 7 in ThreeTen-Backport and additionally adapted for Android in ThreeTenABP (see How to use ... ).
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.