w3resource logo


Java Programming Exercies

Java DateTime, Calendar Exercises: Get today's date at midnight time

Secondary Nav

Java DateTime, Calendar : Exercise-34 with Solution

Write a Java program to get today's date at midnight time.

Java Code:

import java.util.*;
public class Exercise34 {
   public static void main(String[] args)
    {
      Calendar cal = new GregorianCalendar();
      cal.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      System.out.println("\n"+cal.getTime()+"\n");
    
    }
}

Sample Output :

Mon Sep 19 00:00:00 IST 2016 

Java Practice online:

import java.util.*;
public class Exercise34 {
   public static void main(String[] args)
    {
      Calendar cal = new GregorianCalendar();
      cal.set(Calendar.HOUR_OF_DAY, 0); //anything 0 - 23
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      System.out.println("\n"+cal.getTime()+"\n");
    
    }
}



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program