扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

java 获取当前时间的三种方法

扬州沐宇科技
2023-08-11 13:16:23
Java

  1. 使用System.currentTimeMillis()方法获取当前时间的毫秒数:

long currentTime = System.currentTimeMillis();

  1. 使用Date类获取当前时间:

Date date = new Date();

long currentTime = date.getTime();

  1. 使用Calendar类获取当前时间:

Calendar calendar = Calendar.getInstance();

long currentTime = calendar.getTimeInMillis();

扫码添加客服微信