public static void main(String[] args) {
        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date=new Date();
        System.out.print(dateFormater.format(date));
    }

打印结果:

2017-04-28 11:16:21

 字符串转日期:

public static void main(String[] args) {
        String time = "2017-10-23 17:57:10";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            System.out.println(sdf.parse(time));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

打印结果:

Mon Oct 23 17:57:10 CST 2017

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2021-11-27
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案