当前位置:网站首页>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
边栏推荐
- It is urgent for enterprises to protect API security
- 1-7 Path路径模块
- The programmer's girlfriend gave me a fatigue driving test
- 1-1 basic concepts of database
- Deployment and use of Nacos
- FreeRTOS record (IX. an example of a bare metal project transferring to FreeRTOS)
- 1-18 创建最基本的express服务器&创建路由的API模块
- 《ClickHouse原理解析与应用实践》读书笔记(2)
- To the Sultanate of Anderson
- 1-2 安装并配置MySQL相关的软件
猜你喜欢

Study summary of dynamic routing between capsules

AKK菌——下一代有益菌

Introduce an online platform for multi omics integration and network visual analysis

Dm8: generate DM AWR Report

模板方法模式介绍与示例

Anaconda下安装Jupyter notebook

A comprehensive understanding of gout: symptoms, risk factors, pathogenesis and management

Go Web 编程入门: 一探优秀测试库 GoConvey

Jupyter notebook/lab switch CONDA environment

Usbcan analyzer's supporting can and canfd comprehensive test software lkmaster software solves engineers' can bus test problems
随机推荐
1-19 利用CORS解决接口跨域问题
ML&DL:機器學習和深度學習中超參數優化的簡介、評估指標、過擬合現象、常用的調參優化方法之詳細攻略
【回溯】全排列 leetcode46
Introduction to go web programming: a probe into the excellent test library gocovey
PyTorch量化感知训练(QAT)步骤
1-13 express监听GET和POST请求&处理请求
FreeRTOS record (IX. an example of a bare metal project transferring to FreeRTOS)
Ten security measures against unauthorized access attacks
1-15 nodemon
PyTorch量化实践(2)
1-12 preliminary understanding of Express
Sqlserver string type converted to decimal or integer type
根据肠道微生物组重新思考健康饮食
Jupyter notebook/lab switch CONDA environment
5G 在智慧医疗中的需求
Document Layout Analysis: A Comprehensive Survey 2019论文学习总结
NCAT detailed introduction (Reprint)
Usbcan analyzer's supporting can and canfd comprehensive test software lkmaster software solves engineers' can bus test problems
Rethink healthy diet based on intestinal microbiome
The Jenkins download Plug-in can't be downloaded. Solution