import java.text.SimpleDateFormat;
import java.util.Date;public static String getCurrentTimeInstance() throws Exception {
String currentTimeInstance = null;
try {
Date today = Calendar.getInstance().getTime();
// Create our date "formatter" (the date format we want)
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss");
// Create a new String using the date format we want
currentTimeInstance = formatter.format(today);
} catch (Exception e) {
APPLICATION_LOGS.error(e);
}
return currentTimeInstance;}
(OR)
//Returns the current time when the method is called
public String getCurrentTime(){
DateFormat dateFormat =
new SimpleDateFormat("HH:mm:ss:SSS");
Date dt = new Date();
return dateFormat.format(dt);
}
}
No comments:
Post a Comment