当前位置:网站首页>开发技术-获取10分钟前的时间
开发技术-获取10分钟前的时间
2022-06-30 20:35:00 【JustDI-CM】
SimpleDateFormat:用于日期格式化
Calendar:用于时间操作
Date:用于获取时间
java 日期格式化-- SimpleDateFormat 的使用。字符串转日期,日期转字符串
Java Calendar 日历类的时间操作 Timestamp Date Calendar 相互转换
代码1:
// SimpleDateFormat 日期格式化
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar rightNow = Calendar.getInstance();
Date dt = new Date();
System.out.println("当前时间---" + sdf.format(dt));
rightNow.setTime(dt);
rightNow.add(Calendar.MINUTE, -10);
Date dt2 = rightNow.getTime();
String format = sdf.format(dt2);
System.out.println("减少十分钟---" + format);代码2:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
System.out.println("当前时间---" + sdf.format(now));
// 十分钟的毫秒数
// long time = 10 * 60 * 1000;
// 九分半的毫秒数
long time = 570000;
Date beforeDate = new Date(now.getTime() - time);
System.out.println("九分半前---" + sdf.format(beforeDate));代码1只能实现整数功能,代码2比较灵活
边栏推荐
猜你喜欢
随机推荐
What bank card do you need to open an account online? In addition, is it safe to open an account online now?
uniapp-路由uni-simple-router
居家办公没有“血泪史”| 社区征文
Wechat applet development practice cloud music
BioVendor sRAGE Elisa试剂盒测试原理和注意事项
Deflection lock / light lock / heavy lock lock is healthier. How to complete locking and unlocking
Dynamic style binding --style and class
Testing principle and precautions of biovendor rage ELISA Kit
Is it safe to open an account for online stock trading!?
Jenkins can't pull the latest jar package
uniapp怎么上传二进制图片
判断js对象是否为空的方式
Scene 299
Jerry's determination of detection sensitivity level [chapter]
转:用实际行动赢得别人追随
Web host iptables firewall security script
Lingyun going to sea | 10 leap &huawei cloud: jointly helping Africa with inclusive financial services
Lumiprobe nucleic acid quantitative qudye dsDNA br detection kit
Amazon restricts LGBTQ related search and product sales in the United Arab Emirates
为什么vscode用久了电脑速度变慢?








