[英]Convert EEE MMM dd HH:mm:ss ZZZ yyyy to YYYY-MM-dd JAVA
I want to convert : Thu Feb 02 00:00:00 WET 2012
to 02/02/2012
(with date type not string) using JAVA. 我想转换: Thu Feb 02 00:00:00 WET 2012
至02/02/2012
(含日期类型不是字符串)使用JAVA。
I did 我做了
String date = "Thu Feb 02 00:00:00 WET 2012";
SimpleDateFormat formatnow = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZ yyyy", Locale.ENGLISH);
SimpleDateFormat formatneeded=new SimpleDateFormat("YYYY-MM-dd");
Date date1 = formatnow.parse(date);
String date2 = formatneeded.format(date1);
Date date3= formatneeded.parse(date2);
System.out.println(date3);
And I'm having : Thu Feb 02 00:00:00 WET 2012
. 我正在: Thu Feb 02 00:00:00 WET 2012
。 Can anyone tell me where is the problem ?? 谁能告诉我问题出在哪里??
The Date object does not hold any information about the display format you want. Date对象不包含有关所需显示格式的任何信息。 So parsing a date from a formatted date string is not going to 'remember' any formatting. 因此,从格式化的日期字符串中解析日期不会“记住”任何格式。
System.out.println(date3) will print value of date3 using java's toString method. System.out.println(date3)将使用java的toString方法打印date3的值。
You have the formatted date string in date2. 您在date2中具有格式化的日期字符串。 So System.out.println(date2) should give you the right value. 因此,System.out.println(date2)应该为您提供正确的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.