Convert Date Format in Java


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormat {
 public static void main(String[] args) {
  String dateToConvert = "1504201600000";
  SimpleDateFormat oldFormat = new SimpleDateFormat("ddMMyyyyhhmmss");
  Date date = null;
  try {
   date = oldFormat.parse(dateToConvert);
  } catch (ParseException e) {
   System.out.println("Parse Exception error");
   e.printStackTrace();
  }
  System.out.println(date);
  SimpleDateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy");
  String output = newFormat.format(date);
  System.out.println(output);
 }
}


SHARE

About Unknown

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment