SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String s = df.format(currentTimeMillis);//时间戳 转String(2018-02-10 12:03:41)
Date date = new Date();//获取系统当前时间 Sat Feb 10 13:40:03 CST 2018
long time = date.getTime();//date 转时间戳(long 1518235421189)
long currentTimeMillis = System.currentTimeMillis();//获取当前时间戳 1518235421189String s = df.format(currentTimeMillis);//时间戳 转String(2018-02-10 12:03:41)
Date parse = df.parse(s);//String 转date(Sat Feb 10 12:03:41 CST 2018)
Calendar now = Calendar.getInstance();
now.set(Calendar.DATE, now.get(Calendar.DATE)-5);//获取五天前
now.getTimeInMillis()//Calendar 转时间戳
本文介绍如何使用Java进行日期与时间的格式化操作,包括将日期转换为字符串、字符串转换为日期、获取当前时间戳及调整日期等常见应用场景。
2064

被折叠的 条评论
为什么被折叠?



