My source date type is EEE MMM dd HH:mm:ss zzz yyyy
. For example, Sat Dec 12 00:00:00 KST 2020
But my target date type is Java Date type with format yyyy-MM-dd
. So I make the method which convert Java String type EEE MMM dd HH:mm:ss zzz yyyy
to java util object.
private static Date getDate(String beforeDate) throws Exception{ SimpleDateFormat readFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); Date rdate = readFormat.parse(beforeDate); SimpleDateFormat writeFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); String format = writeFormat.format(rdate); System.out.println(format); return writeFormat.parse(format); }
System.out.println(format)
line prints the right values which I expect.
2020-12-12 2020-12-12 2013-01-01
But the type of return values is wrong. The return value from the method seems not to be influenced.
System.out.println(getDate("Sat Dec 12 00:00:00 KST 2020"));
The above line prints Sat Dec 12 00:00:00 KST 2020
again. I have no idea which codes are wrong in converting Java date type. Any advice will be appreciated. Best regards
没有评论:
发表评论