24 -hour time display :
public class Datetime {
public static void main(String args[]){
java.util.Date current=new java.util.Date();
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String c=sdf.format(current);
System.out.println(c);
}
}
12 -hour time display :
public class Datetime {
public static void main(String args[]){
java.util.Date current=new java.util.Date();
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String c=sdf.format(current);
System.out.println(c);
}
}
difference between the two : yyyy-MM-dd HH: mm: ss; yyyy-MM-dd hh: mm: ss
It truly helped out. Awesome!
回复删除