DateFormat

 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;

 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //HH - 24小时
 //yyyy-MM-dd hh:mm:ss.SSS - 12小时

 String dateStr = "2008-01-17 23:05:22.0";
 long maxLoginTime = DBUtil.getDateTime(dateStr);

 Calendar cal = Calendar.getInstance();
 cal.setTimeInMillis(maxLoginTime);
 Date date = cal.getTime();
 String loginTime = df.format(date);

 #   public static long getDateTime(String date){
  #      long dateTime = 0L;
   #     try {
   #         dateTime = df.parse(date).getTime();
  #      } catch (ParseException ex) {
   #     }
 #       return dateTime;
  #  }

你可能感兴趣的:(java)