I am developing a spring application and in one of my controller i have following lines to parse from string to date and format the parsed date to required format. But again i need to parse back formatted string into date without using any SimpleDateFormat, so is it possible to do so ?
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
Date pick=dateFormat.parse(request.getParameter("pickDate"));
String pick_date=dateFormat2.format(pick);
Edit:
I found in the wikipedia that china has the locale yyyy-MM-dd. check this reference date format by country set locale to China you'll get the required date format
Try this
String d1="12-27-2010";
Stirng[] splitdata=d1.split("-");
int month=Integer.parseInt(splitdata[0]);
int day=Integer.parseInt(splitdata[1]);
int year=Integer.parseInt(splitdata[2]);
Calender cal=Calender.getInstance(Locale.CHINA);
cal.set(year,month,day);
Date d=cal.getTime();
This should work
If you know your data format you can do that. by using simple string operations
Ex: if your data format is
MM-dd-yyyy
then you can convert to yyyy-MM-dd
like this
String d1="12-27-2010";
Stirng[] splitdata=d1.split("-");
String s2= splitdate[2]+"-"+splitdate[0]+"-"+splitdate[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With