After
I want to parse a string by date, like the date format Tuesday March 19, 2012 . I want to parse and format it in the format
yyyy-dd-mm
. The exception to the code given below is that "unceasing date"
Code:.
DateFormat DF1 = New SimpleDateFormat ("yyyy-MM-dd"); Try {date1 = df1.parse (currentDate); System.out.println ("============ My formatted date ====================" + date1.toString ()) ; Calendar cal = calendar.justinstance (); Cal.setTime (DATE1); Cal.add (Calendar.Det, 10); // add 10 day date 1 = cal.getTime (); Println ("============== Added date ==============" + date1.toString ());
I have created a common function for the changed date format. You pass the old date format, new date format and date // Call the Frequency
public static string convertDateFormat (string oldFormat, string newFormat, string inputDate) {DateFormat theDateFormat = New SimpleDateFormat (oldFormat). Date date = null; Try {date = theDateFormat.parse (inputDate); } Hold (ParseException parseException) {// Date is invalid what you have to do. } Hold (exception exception) {// normal grip what you have to do. } TheDateFormat = New SimpleDateFormat (newFormat); Back to theDateFormat.format (date) .toString (); }
String Converted Data = Convert Format ("EEEE MMM dd, yyyy", "yyyy-MM-dd", dateToConvert) ;
No comments:
Post a Comment