Java中时间戳的使用

MiaoMiaoAiDaPi2 2023-01-30 22:01:33

原文链接

当前时间

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

 
 

学习更多编程知识,请关注我的公众号:

代码的路

...全文
146 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

82

社区成员

发帖
与我相关
我的任务
社区描述
编程技术分享,包括深度学习、Python、Java等技术
pythonjavac++ 个人社区 北京·西城区
社区管理员
  • 代码的路
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

编程知识分享,一起学习,一起进步!

试试用AI创作助手写篇文章吧