Here are two ways to do it in Java:

/*
 *  Add the TimeZone info to the end of the date:
 */

String dateString = "2012-11-13 14:00:00:000";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d H:m:s:S Z");
Date theDate = sdf.parse(dateString + " UTC");

/*
 *  Use SimpleDateFormat.setTimeZone()
 */

String dateString = "2012-11-13 14:00:00:000";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d H:m:s:S");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date theDate = sdf.parse(dateString);

Note that Date.parse() is deprecated (so I did not recommend it).

Answer from jahroy on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java dates › get date without time in java
Get Date Without Time in Java | Baeldung
March 12, 2025 - In the next sections, we’ll show some common workarounds to tackle this problem. One of the most common ways to get a Date without time is to use the Calendar class to set the time to zero.
🌐
CodeProject
codeproject.com › Tips › 1190426 › When-Parsing-Formatting-Dates-in-Java-Make-Sure-Yo
When Parsing/Formatting Dates in Java, Make Sure You Don't Rely on the Default Behavior - CodeProject
Alternatively, instead of specifying explicitly, you can run JVM with the parameter which overrides the time zone with the required one, e.g. -Duser.timezone=UTC, or even set default timezone globally for your application:
🌐
Medium
mbavatharany.medium.com › date-and-time-9118eaac95b4
Date, Time and TimeZone in Java. Working with date and time is really a… | by Bavatharany Mahathevan | Medium
January 8, 2022 - ZonedDate and Time : Developers have to handle the timezone logic additionally. Java 8 provides more support for the date and Time functionalities with the classes like LocalDate, LocalTime, LocalDateTime, Instant, Period, Duration and TemporalUnit in java.time package. Let's see one by one. ... It represents only a date without time or time zone.
🌐
GitHub
github.com › pgjdbc › pgjdbc › issues › 2221
LocalDate conversion should ignore timezones · Issue #2221 · pgjdbc/pgjdbc
May 24, 2021 - Expected behaviour The resulting LocalDate contains exactly the same date as the database field, since java.time.LocalDate is a date without a time-zone and therefore time-zone differences between database and application should not affect the date.
Published   Aug 02, 2021
🌐
Herongyang
herongyang.com › JDK › Time-java-time-LocalDateTime-Class-Local-Date-Time.html
java.time.LocalDateTime - Local Date and time without Timezone
The java.time.LocalDateTime class is designed mainly for manipulating local times without any specific timezone to support local daily activities, like celebrating New Year Eve at Dec 31, 23:59:59.000 local time.
Find elsewhere
🌐
How to do in Java
howtodoinjava.com › home › java date time › converting date and time between timezones
Converting Date and Time between Timezones - HowToDoInJava
October 1, 2022 - OffsetDateTime now = ...14.509742500+05:30 2022-02-16T13:06:14.509742500Z[UTC] java.util.Date represents a time instant without timezone information....
🌐
GitHub
github.com › pgjdbc › pgjdbc › issues › 2850
LocalDateTime conversion to timestamp without time zone is affected by JVM timezone at DST boundary · Issue #2850 · pgjdbc/pgjdbc
March 13, 2023 - LocalDateTime conversion to timestamp without time zone is affected by JVM timezone at DST boundary#2850 ... Description When using a java LocalDateTime set to the DST transition hour in the JVM's timezone as a parameter in a query, the value ...
Published   Mar 13, 2023
Top answer
1 of 2
16

A Timestamp doesn't have a timezone. When you display the timestamp as a String, it displays a time and mentions the timezone, because else you couldn't know what time it represents. And it chooses to use the default timezone (yours), because that's the one you're the most familiar with.

Saying, it's 12:00:00 doesn't mean anything. Saying it's 12:00:00 in your timezone means something. But the timestamp only contains an instant in time. You may display this instant in time in any time zone you want using a DateFormat.

Note: Timestamp.valueOf("2010-10-23 12:05:16"); means "create a timestamp with the given time in the default timezone".

2 of 2
5

tl;dr

… can I create a java.sql.timestamp without timezone …

No, you cannot. Wrong class. Use java.time.LocalDateTime instead.

Details

A java.sql.Timestamp is the wrong class to use. It represents a moment in UTC with a resolution of nanoseconds.

If you want a date with time-of-day irrespective of time zone or offset-from-UTC (so, not a moment), use another class that is fit-for-purpose.

By the way… The java.sql.Timestamp is a terrible old class badly designed, and was supplanted years ago by the class java.time.Instant (always in UTC) or alternatively java.time.OffsetDateTime if set to an offset of UTC.

LocalDateTime

The proper class for a date with time-of-day without any concept of time zone or offset-from-UTC is LocalDateTime.

As noted above, this means this class is not a moment, not a point on the timeline, and should not be used to track actual points of time when an event happened in some place.

TIMESTAMP WITHOUT TIME ZONE

In a SQL-standard compliant database such as Postgres, use a column of data type TIMESTAMP WITHOUT TIME ZONE (not the WITH type).

LocalDateTime ldt = myResultSet.getObject( … , LocalDateTime.class ) ;

And…

myPreparedStatement.setObject( … , ldt ) ;

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.

You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes.

Where to obtain the java.time classes?

  • Java SE 8, Java SE 9, Java SE 10, Java SE 11, and later - Part of the standard Java API with a bundled implementation.
    • Java 9 adds some minor features and fixes.
  • Java SE 6 and Java SE 7
    • Most of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
  • Android
    • Later versions of Android bundle implementations of the java.time classes.
    • For earlier Android (<26), the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….

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.

Top answer
1 of 5
8

This Question and the Answers are now outmoded. They use old date-time classes outmoded by the java.time framework built into Java 8 and later. The old classes are poorly designed, confusing, and troublesome; Avoid them.

Avoid 3-4 Letter Zone Codes

Avoid the 3-4 letter codes such as BST. They are neither standardized nor unique. They do not actually represent time zones. And they add even more confusion to the problem of Daylight Saving Time (DST).

Instead, use proper time zones. Most are continent/region format such as Europe/London.

Avoid setting default time zone

Calling java.util.TimeZone.setDefault should be done only in the most extreme cases. This call affects all code running in all threads of all apps within the JVM immediately during runtime.

Instead, in all your date-time code, specify the desired/expected time zone. If omitted, Java falls back by implicitly relying on the JVM’s current default time zone. As noted above this default can change at any moment during runtime! Instead, specify explicitly. If you specify your desired/expected time zone as a passed argument routinely then the current default time zone is moot, irrelevant.

java.time

The java.time framework is built into Java 8 and later. See Tutorial. Defined by JSR 310. Inspired by the highly successful Joda-Time library.

Instant

An Instant is a moment on the timeline in UTC.

The following example shows how the java.time classes can parse/generate strings by default if in standard ISO 8601 format, with no need to specify a parsing pattern. Use DateTimeFormatter class to specify other non-standard patterns.

Instant instant = Instant.parse( "2011-12-27T09:00:00Z" );

ZonedDateTime

Apply a time zone as needed, producing a ZonedDateTime.

ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = instant.atZone( zoneId );

Generating Strings

You can produce textual representations of the ZonedDateTime object using a DateTimeFormatter. You can specify custom patterns. Or, as I recommend, let java.time localize for you.

DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.MEDIUM );

Best to specify the desired/expected Locale for the same reason as time zone… the JVM’s current default can be changed at any moment by any code in any thread of any app running within the JVM. The Locale determines (a) the human language used for names of day & month, and (b) the cultural norms such as commas versus periods and the order of the parts such as month or day or year coming first.

formatter = formatter.withLocale( Locale.CANADA_FRENCH );
String output = zdt.format( formatter );

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.

You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes.

Where to obtain the java.time classes?

  • Java SE 8, Java SE 9, Java SE 10, Java SE 11, and later - Part of the standard Java API with a bundled implementation.
    • Java 9 adds some minor features and fixes.
  • Java SE 6 and Java SE 7
    • Most of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
  • Android
    • Later versions of Android bundle implementations of the java.time classes.
    • For earlier Android (<26), the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….

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.

2 of 5
4

I think that you are using the correct pattern for your requirements, however the JDK doesn't know the name of your timezone, so it switches over to using a GMT offset value instead.

When I format a date using your pattern, I get "GMT" for the timezone part.

What does TimeZone.getDefault().getDisplayName() give you? For me, I get "Greenwich Mean Time".

🌐
Oracle
docs.oracle.com › javase › tutorial › datetime › iso › timezones.html
Time Zone and Offset Classes (The Java™ Tutorials > Date Time > Standard Calendar)
The Date-Time API provides three ... time zone with a time zone offset from Greenwich/UTC. OffsetDateTime handles a date and time with a corresponding time zone offset from Greenwich/UTC, without a time zone ......
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › time › DateFormatUtils.html
DateFormatUtils (Apache Commons Lang 3.20.0 API)
ISO 8601 formatter for date-time without time zone. The format used is yyyy-MM-dd'T'HH:mm:ss. This format uses the default TimeZone in effect at the time of loading DateFormatUtils class.
Top answer
1 of 3
21

Adding a bit more info and examples to the correct answers (accepted answer and other one).

UPDATE Added section at end on java.time classes. These supplant Joda-Time.

Purpose of LocalDateTime

You may be confused about the purpose of LocalDateTime.

If trying to represent a date-time value using "wall clock time" as seen by someone in a locality looking at their own clock and calendar, then adjust the time zone of the DateTime object to suit the desired locality.

LocalDateTime is not meant for a particular locality but for the general idea of date+time. For example, "This year's Christmas starts at midnight on December 25, 2014". Conceptually, that is a LocalDateTime, intended to mean different moments in Paris than Montréal and Auckland.

Adjusting Time Zone

Use the DateTimeZone class in Joda-Time to adjust to a desired time zone. Joda-Time uses immutable objects. So rather than change the time zone ("mutate"), we instantiate a new DateTime object based on the old but with the desired difference (some other time zone).

Use proper time zone names. Generally a continent/cityOrRegion.

DateTimeZone zoneParis = DateTimeZone.forID( "Europe/Paris" );
DateTimeZone zoneMontréal = DateTimeZone.forID( "America/Montreal" );
DateTimeZone zoneAuckland = DateTimeZone.forID( "Pacific/Auckland" );

Parse string, assign a time zone, adjust to other time zones.

DateTime dateTimeParis = new DateTime( "2015-07-09T05:10:00+02:00" , zoneParis );
DateTime dateTimeMontréal = dateTimeParis.withZone( zoneMontréal );
DateTime dateTimeAuckland = dateTimeParis.withZone( zoneAuckland );

Dump to console.

System.out.println( "dateTimeParis: " + dateTimeParis );
System.out.println( "dateTimeMontréal: " + dateTimeMontréal );
System.out.println( "dateTimeAuckland: " + dateTimeAuckland );

When run.

dateTimeParis: 2015-07-09T05:10:00.000+02:00
dateTimeMontréal: 2015-07-08T23:10:00.000-04:00
dateTimeAuckland: 2015-07-09T15:10:00.000+12:00

Localize Using Formatted Strings

Joda-Time can translate to a particular locale’s language and customary style when creating a string representation of your date-time object.

DateTimeFormatter formatterMontréal = DateTimeFormat.forStyle( "FF" ).withZone( zoneMontréal ).withLocale( Locale.CANADA_FRENCH );
String outputMontréal = formatterMontréal.print( dateTimeParis );
System.out.println( "outputMontréal: " + outputMontréal );

When run:

outputMontréal: mercredi 8 juillet 2015 23 h 10 EDT

java.time

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes. The Joda-Time framework inspired java.time, so concepts are quite similar.

ZoneId and ZoneOffset are the two classes to represent a time zone and offset-from-UTC respectively. An offset is merely a number of hours and minutes and seconds. A time zone is an offset plus a set of rules for handling anomalies such as Daylight Saving Time (DST).

ZoneId zoneParis = ZoneId.of( "Europe/Paris" );
ZoneId zoneMontreal = ZoneId.of( "America/Montreal" );
ZoneId zoneAuckland = ZoneId.of( "Pacific/Auckland" );

The primary date-time classes in java.time are:

  • Instant – A moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction).
  • OffsetDateTime – An Instant plus a ZoneOffset.
  • ZonedDateTime – An Instant plus a ZoneId.

The java.time classes use ISO 8601 standard formats by default when parsing/generating strings representing date-time values. So no need to specify a formatting pattern with such inputs.

This input here indicates an offset-from-UTC but not a full time zone. So we parse as an OffsetDateTime rather than a ZonedDateTime.

OffsetDateTime odt = OffsetDateTime.parse( "2015-07-09T05:10:00+02:00" );

As the basic building-block of java.time, always in UTC by definition, you may want to extract an Instant.

Instant instant = odt.toInstant();  // `Instant` is always in UTC by definition.

You can adjust into a time zone.

ZonedDateTime zdtParis = odt.atZoneSameInstant( zoneParis );
ZonedDateTime zdtMontreal = odt.atZoneSameInstant( zoneMontreal );
ZonedDateTime zdtAuckland = zdtMontreal.withZoneSameInstant( zoneAuckland );

Localize via the DateTimeFormatter class.

DateTimeFormatter f = DateTimeformatter.ofLocalizedDateTime( FormatStyle.FULL ).withLocale( Locale.CANADA_FRENCH );
String output = zdtMontreal.format( f );

See live code in IdeOne.com.

odt: 2015-07-09T05:10+02:00

instant: 2015-07-09T03:10:00Z

zdtParis: 2015-07-09T05:10+02:00[Europe/Paris]

zdtMontreal: 2015-07-08T23:10-04:00[America/Montreal]

zdtAuckland: 2015-07-09T15:10+12:00[Pacific/Auckland]

output: mercredi 8 juillet 2015 23 h 10 EDT


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 ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
    • 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.

2 of 3
14

What @Nazgul said is right, but in case all you want to achieve is a "wall-time" in UTC zone you can do something like that:

DateTime dateTimePlus2 = DateTime.parse("2015-07-09T05:10:00+02:00");
System.out.println(dateTimePlus2);

DateTime dateTimeUTC = dateTimePlus2.withZone(DateTimeZone.UTC);
System.out.println(dateTimeUTC);

LocalDateTime localDateTimeUTC = dateTimeUTC.toLocalDateTime();
System.out.println(localDateTimeUTC);

Result:

2015-07-09T05:10:00.000+02:00
2015-07-09T03:10:00.000Z        ("Z" == Zulu tz == UTC)
2015-07-09T03:10:00.000

As you can see, the time is not "07:10" as you expected, because UTC+2 zone is two hours ahead of UTC. Converting to UTC subtracts 2 hours.