当前时间
import java.sql.Timestamp; //导包
Timestamp nowTime = new Timestamp(System.currentTimeMillis());
System.out.println(nowTime);
输出:
2022-06-08 11:15:51.014
Long型时间戳
Long timeLong = System.currentTimeMillis();
System.out.println("timeString:" + timeLong + "\n");
输出:
1652862076686
时间戳转格式
Long timeLong = System.currentTimeMillis();
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置格式
String timeString = timeFormat.format(timeLong);
System.out.println("timeString:" + timeString + "\n");
输出:
2022-06-08 11:15:51
学习更多编程知识,请关注我的公众号:
代码的路