当前位置:网站首页>获取系统当前日期
获取系统当前日期
2022-06-28 10:51:00 【Hello_xzy_Word】
获取系统当前日期
有些时候,我们只需要获取当前的年月日信息,在一些老的系统中,可能使用如下语句:
public class Main {
public static void main(String[] args) {
Date today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
}
}
目前,Date 类的 setHours 、 setMinutes 、setSeconds 方法已经被标注为弃用,并且,推荐编程人员改用 Calendar 类的 set 方法操作时间:

下面是通过使用Calendar 类的 set 方法获取系统当前日期的代码:
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Date today = calendar.getTime();
}
}
边栏推荐
- Understanding of FTP protocol
- sentinel
- DlhSoft Kanban Library for WPF
- [cloud resident co creation] detailed introduction to DWS alarm service DMS and cluster connection mode
- How to use output in katalon
- Google open source dependency injection framework Guice Guide
- 满电出发加速品牌焕新,长安电动电气化产品吹响“集结号”
- JS基础5
- Ruoyi integrated building block report (NICE)
- Does flink1.15 support MySQL views? I configured the view name at the table name to save, but the table could not be found. Think
猜你喜欢

Threads and thread pools

移动命令

线程和线程池

JS基础3

Training and recognition of handwritten digits through the lenet-5 network built by pytorch

Information hidden in the trend chart of Hong Kong London gold market

Understand 12 convolution methods (including 1x1 convolution, transpose convolution and deep separable convolution)

Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison

mysql数据库概述以及安装过程

Debug debugging in katalon
随机推荐
如何利用k线图做技术分析
Training and recognition of handwritten digits through the lenet-5 network built by pytorch
【功能建议】多个工作空间启动时选择某个空间
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
Spatial-Temporal时间序列预测建模方法汇总
Compression and decompression
MySQL (III)
Bytecode proof in appliedzkp zkevm (9)
MySQL(二)
MySQL查看数据库性能常用命令
[QT] connect syntax reference implementation
2022 Wu Enda machine learning specialization week 2 practice lab: linear expression
线程和线程池
Hystrix deployment
AQS understanding
OpenHarmony应用开发之二维码生成器
无线模块透明传输技术的物联网应用案例
Installing MySQL database (CentOS) in Linux source code
Katalon global variable is referenced in testobject
JS基础6