当前位置:网站首页>Develop technology - get time 10 minutes ago
Develop technology - get time 10 minutes ago
2022-06-30 21:49:00 【JustDI-CM】
SimpleDateFormat: Used for date formatting
Calendar: For time operation
Date: Used to get the time
java Date formatting -- SimpleDateFormat Use . String to date , Date to string
Java Calendar Calendar time operation Timestamp Date Calendar transformation
Code 1:
// SimpleDateFormat Date formatting
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar rightNow = Calendar.getInstance();
Date dt = new Date();
System.out.println(" current time ---" + sdf.format(dt));
rightNow.setTime(dt);
rightNow.add(Calendar.MINUTE, -10);
Date dt2 = rightNow.getTime();
String format = sdf.format(dt2);
System.out.println(" Ten minutes less ---" + format);
Code 2:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
System.out.println(" current time ---" + sdf.format(now));
// The number of milliseconds in ten minutes
// long time = 10 * 60 * 1000;
// Nine and a half milliseconds
long time = 570000;
Date beforeDate = new Date(now.getTime() - time);
System.out.println(" Nine and a half minutes ago ---" + sdf.format(beforeDate));
Code 1 Only integer function can be realized , Code 2 More flexible
边栏推荐
- PyTorch量化实践(2)
- ceshi deces
- 将el-table原样导出为excel表格
- Reading notes of Clickhouse principle analysis and Application Practice (1)
- Test medal 1234
- 用yml文件进行conda迁移环境时的报错小结
- 本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
- Pytorch quantitative perception training (qat) steps
- Akk bacteria - the next generation of beneficial bacteria
- “信任机器”为发展赋能
猜你喜欢
jenkins下载插件下载不了,解决办法
Bloom filter
Phoenix architecture: an architect's perspective
兴奋神经递质——谷氨酸与大脑健康
一文读懂什么是MySQL索引下推(ICP)
《Dynamic Routing Between Capsules》论文学习总结
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
Neurotransmetteurs excitateurs - glutamate et santé cérébrale
Reading notes of Clickhouse principle analysis and Application Practice (2)
qsort函数和模拟实现qsort函数
随机推荐
To the Sultanate of Anderson
全面认识痛风:症状、风险因素、发病机理及管理
NCAT detailed introduction (Reprint)
[untitled] first time to participate in CSDN activities
1-20 pre inspection request
sdfsdf
兴奋神经递质——谷氨酸与大脑健康
Introduction and example of template method mode
Arcmap|assign values to different categories of IDS with the field calculator
Can flinksql two Kafka streams join?
1-19 using CORS to solve interface cross domain problems
1-2 install and configure MySQL related software
Dm8: generate DM AWR Report
1-19 利用CORS解决接口跨域问题
1-17 express Middleware
本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
1-1 数据库的基本概念
AKK菌——下一代有益菌
[grade evaluator] how to register a grade evaluator? How many passes?