I need to obtain a Date object from this String:This is a example)
M-27\nJUN-2012 DayOfWeek-dd\nMONTH-yyyy
Its impossible? I dont know how to use simpledateformat for this..The \n is a line jump.
I need to obtain a Date object from this String:This is a example)
M-27\nJUN-2012 DayOfWeek-dd\nMONTH-yyyy
Its impossible? I dont know how to use simpledateformat for this..The \n is a line jump.
The documentation for SimpleDateFormat doesn't seem to do days of the week as single letters. I would take a substring that removes that letter and the dash with it:
27\nJUN-2012
Then I would use dd\nMMM-yyyy
as the string you use in the constructor of the SimpleDateFormat.
This should do exactly what you want. Since you have the day of the month as a number, the day of the week doesn't matter that much to you to create the date object. If you really want to know the day of the week, then see here: How to determine day of week by passing specific date?
Try following SimpleDateFormat:
String dateS = "M-27\nJUN-2012"; // your date string
SimpleDateFormat fmt = new SimpleDateFormat("dd\nMMM-yyyy"); // formatter
Date date = fmt.parse(dateS.substring(2));
System.out.println(date);
You can really drop out the day of week, because day, month and year defines this day.