获取当前毫秒数

long t=System.currentTimeMillis();

毫秒数转换为时间

Date date = new Date();
long t=System.currentTimeMillis();
date.setTime(t);
System.out.println(date);

时间格式化

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
String fmDate=simpleDateFormat.format(new Date());

字符串格式时间获取毫秒数

String sdate = "2020-06-01 06-06-06";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
long time = simpleDateFormat.parse(sdate).getTime();

时间插入数据库

先转换成yyyy-MM-dd HH:mm:ss这个格式,然后可以以字符串格式插入

Date date=new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String fmDate=simpleDateFormat.format(date);

参考博客:https://blog.csdn.net/sinat_32238399/article/details/80512452


Last modification:April 7, 2020
如果觉得我的文章对你有用,请随意赞赏