Get Today's date in Java at midnight time

前端 未结 12 2014
北海茫月
北海茫月 2020-12-09 07:08

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

  • date object d1 should be 9th March 20
12条回答
  •  粉色の甜心
    2020-12-09 08:06

    Calendar currentDate = Calendar.getInstance(); //Get the current date
    SimpleDateFormat formatter= new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss"); //format it as per your requirement
    String dateNow = formatter.format(currentDate.getTime());
    System.out.println("Now the date is :=>  " + dateNow);
    

提交回复
热议问题