Date Formatting
We can use below code to format a required field to specific date format.
If date format is 2017-08-07 then we can change it to any format(eg:dd-MMM-yyyy HH:mm:ss)
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
try {
Date dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(assmovedate);
System.out.println("date captured!!!!"+dt);
Date dt1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(assreturningdate);
System.out.println("date captured!!!!"+dt1);
System.out.println(formatter.format(dt));
System.out.println(formatter.format(dt1));
String assetmovedate = (String)formatter.format(dt); // Asset Move date converted to date format
System.out.println("new date format" +assetmovedate);
String assetreturningdate = (String)formatter.format(dt1); // Asset returning date converted to date format
System.out.println("new date format 1" +assetreturningdate);
}
catch (ParseException e)
{
e.printStackTrace();
}
0 Comments