tl;dr
ZonedDateTime
.parse(
"Sat Dec 12 00:00:00 KST 2020" ,
DateTimeFormatter
.ofPattern( "EEE MMM dd HH:mm:ss zzz uuuu" )
.withLocale( Locale.US )
)
.toLocalDate()
.toString()
2020-12-12
Avoid legacy date-time classes
You are using terrible date-time classes that were supplanted years ago by the modern java.time classes. Never use Date
, Calendar
, or SimpleDateFormat
.
You said:
my target date type is Java Date type with format yyyy-MM-dd.
Apparently, you expect Date
to hold a date. It does not. The java.util.Date
class represents a moment, a date with time-of-day as seen in UTC. The java.sql.Date
class pretends to hold only a date, but it too actually contains a date with time-of-day as seen in UTC.
Among the many problems with java.util.Date
class is the behavior of its toString
method. That method dynamically applies the JVM’s current default time zone while generating text. This anti-feature may contribute to your confusion.
LocalDate
Instead you should be using java.time.LocalDate
to represent a date-only value without a time-of-day and without a time zone or offset-from-UTC.
ZonedDateTime
First use the DateTimeFormatter
class to parse your entire input string. This results in a ZonedDateTime
object representing a moment as seen through the wall-clock time used by the people of a particular region.
Example code
String input = "Sat Dec 12 00:00:00 KST 2020" ;
DateTimeFormatter f = DateTimeFormatter.ofPattern( "EEE MMM dd HH:mm:ss zzz uuuu" ).withLocale( Locale.US ) ;
ZonedDateTime zdt = ZonedDateTime.parse( input , f ) ;
From that ZonedDateTime
object, extract a LocalDate
.
LocalDate localDate = zdt.toLocalDate() ;
See this code run live at IdeOne.com.
zdt.toString(): 2020-12-12T00:00+09:00[Asia/Seoul]
ld.toString(): 2020-12-12
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
.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
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. Hibernate 5 & JPA 2.2 support java.time.
Where to obtain the java.time classes?