jav获取日期 时分秒为0
时间: 2024-04-24 08:27:33 浏览: 262
要获取Java中的日期,并将时分秒设置为0,可以使用以下代码:
```java
import java.util.Calendar;
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);
calendar.set(Calendar.MILLISECOND, 0);
System.out.println(calendar.getTime());
}
}
```
这段代码使用`Calendar`类来获取当前日期,并将时、分、秒和毫秒都设置为0。最后,通过`getTime()`方法将`Calendar`对象转换为`Date`对象并打印出来。这样就可以得到日期的时分秒都为0的结果。
#### 引用[.reference_title]
- *1* [java日期格式(年月日时分秒毫秒)](https://blog.csdn.net/weixin_39957934/article/details/117538153)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [java的日期格式使用](https://blog.csdn.net/weixin_39994665/article/details/111526553)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Java输出当前的日期(年月日时分秒毫秒)](https://blog.csdn.net/weixin_32512187/article/details/112028586)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文