String->Date || Date->String

1.Date转String

    Date date = new Date();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String dateTime = sdf.format(date);

2.String 转Date

    String dateTime = "2019-01-01 01:01:01";
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       try {
           Date date = sdf.parse(dateTime);
       } catch (ParseException e) {
           e.printStackTrace();
       }
上一篇:aes,mysql端加密和java加密能保持一致


下一篇:Java 判断时间是否超过24小时