在午夜时间在Java中获取今天的日期 [英] Get Today's date in Java at midnight time

查看:80
本文介绍了在午夜时间在Java中获取今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建两个日期对象。如果当前日期和时间是2012年3月9日上午11:30,那么

I need to create two date objects. If the current date and time is March 9th 2012 11:30 AM then



  • 日期对象d1应为 2012年3月9日12:00 AM

  • 日期对象d2应包含当前日期本身

日期不会输入,系统日期。

The date will not be entered, it is system date.

更新

Date dt = new Date();
System.out.print(dt.toString());

给出当前日期和时间

推荐答案

    Calendar c = new GregorianCalendar();
    c.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    Date d1 = c.getTime(); //the midnight, that's the first second of the day.

应为Fri Mar 09 00:00:00 IST 2012

should be Fri Mar 09 00:00:00 IST 2012

这篇关于在午夜时间在Java中获取今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆