在Java中,获取当前日期最简单的方法之一就是直接实例化位于Java包java.util的Date类。

Date date = new Date(); // this object contains the current date value
上面获取到的日期也可以被format成我们需要的格式,例如:

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.println(formatter.format(date));

相关文章:

  • 2021-06-29
  • 2022-12-23
  • 2022-01-02
  • 2021-06-03
  • 2021-06-02
  • 2022-12-23
  • 2021-04-24
猜你喜欢
  • 2021-07-26
  • 2022-01-31
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案