在使用SimpleDateFormat时格式化时间的 yyyy.MM.dd 为年月日而如果希望格式化时间为12小时制的,则使用hh:mm:ss 如果希望格式化时间为24小时制的,则使用HH:mm:ss
Date d = new Date();
SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
System.out.println(ss.format(d));
Date date = new Date();
SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
String LgTime = sdformat.format(date);
System.out.println(LgTime);
结果为
2008-05-2801:32:54
2008 - 05 - 28 13 : 32 : 54