在Java中转换日期字符串格式
我正在接收此格式的日期字符串在Java中转换日期字符串格式,java,date,Java,Date,我正在接收此格式的日期字符串dd-MMM-yyyy我打算通过尝试解析字符串将字符串转换为格式yyy-MM-dd,但我收到一个错误 Unparseable date: 01-AUG-2014 我正在努力做到: SimpleDateFormat form new SimpleDateFormat ("yyyy-MM-dd"); String datefrom = "01-AUG-2014" Date dfrom = form.parse(datefrom);//getting error here
dd-MMM-yyyy
我打算通过尝试解析字符串将字符串转换为格式yyy-MM-dd
,但我收到一个错误
Unparseable date: 01-AUG-2014
我正在努力做到:
SimpleDateFormat form new SimpleDateFormat ("yyyy-MM-dd");
String datefrom = "01-AUG-2014"
Date dfrom = form.parse(datefrom);//getting error here
如何将字符串
01-AUG-2014
转换为2014-08-01
?它应该是dd-MMM-yyyy
而不是使用MMM
作为要解析的月份名称,而不是对解析得到的日期对象使用格式
例如
但是这会给我相同格式的日期,我想要yyyy-MM-dd格式的日期。我不想把字符串转换成日期。我想将其重新格式化为其他格式,但将其保留为字符串。
SimpleDateFormat form = new SimpleDateFormat ("dd-MMM-yyyy");//For parsing
String datefrom = "01-Aug-2014";
Date date=form.parse(datefrom);
SimpleDateFormat myForm = new SimpleDateFormat ("yyyy-MM-dd");//for formating
System.out.println(myForm.format(date));//new formatted String
//String formatterDate=myForm.format(date);