当前位置:网站首页>获取系统当前日期
获取系统当前日期
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();
}
}
边栏推荐
猜你喜欢

【实操】Appium Settings app is not running after 5000ms

Realization of a springboard machine

How does ETF position affect spot gold price?

Dataease installation upgrade

Installing MySQL database (CentOS) in Linux source code

JS基础8

无线通信模块定点传输-点对多点的具体传输应用

Ruoyi integrated building block report (NICE)

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

Move command
随机推荐
Metersphere uses JS to refresh the current page
Ribbon core source code analysis
压缩解压
Please consult me. I run the MYSQL to MySQL full synchronization of flykcdc in my local ide. This is in my local ide
Metersphere实现UI自动化元素不可点击(部分遮挡)
To enhance the function of jupyter notebook, here are four tips
Compression and decompression
JSON module, hashlib, Base64
【agora】get 一个 agora_refptr 对象的用法示例
Redis数据库
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
Bytecode proof in appliedzkp zkevm (9)
An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
2D code generator for openharmony application development
Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
Katalon当中的debug调试
广州海关支持保障食品、农产品和中药材等民生物资稳定供港
Transactions proof in appliedzkp zkevm (10)
MySQL(二)
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)