Thursday, November 9, 2017

Time-stamp in Java

public class CalendarClass {

 public static String timeStamp() throws Exception{

  DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
  Calendar cal = Calendar.getInstance();
  String date = dateFormat.format(cal.getTime());
  return date;
}
}


Output: 2017-11-09 16-26-35

No comments:

Post a Comment