Calendar类,专门用于转换特定时刻和日历字段之间的日期和时间。

使用Calendar 获取当前日期和时间非常简单:

Calendar calendar = Calendar.getInstance(); // gets current instance of the calendar
与date一样,我们也可以非常轻松地format这个日期成我们需要的格式

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.println(formatter.format(calendar.getTime()));
上面代码打印的结果如下:

25-11-2018 00:43:39

相关文章:

  • 2021-05-20
  • 2021-09-22
  • 2021-10-16
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-12-29
相关资源
相似解决方案