-3

Is it possible to get system date with time 00:00:00,below is the code i am using--

DateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
java.util.Date date3 = new java.util.Date();
output-Thu jul 10 10:31:12 EDT 2014

I want the result like this----Thu jul 10 00:00:00 EDT 2014

it should be in Date format not in String. please help me out.

user3823948
  • 11
  • 1
  • 5
  • 1
    see this http://developer.android.com/reference/java/text/SimpleDateFormat.html – MilapTank Jul 10 '14 at 05:04
  • possible duplicate of [How to obtain the start time and end time of a day?](http://stackoverflow.com/questions/10308356/how-to-obtain-the-start-time-and-end-time-of-a-day) – Basil Bourque Jul 10 '14 at 07:14

3 Answers3

4

You can use calendar object to set the time.

Calendar calendar=Calendar.getInstance();
calendar.setTime(date3);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Rasive
  • 1,143
  • 1
  • 8
  • 20
mehere
  • 1,487
  • 5
  • 28
  • 50
0

a quick and dirty solution

    DateFormat dateFormat = new SimpleDateFormat("MMMM dd 00:00:00 yyyy");
    System.out.println(dateFormat.format (new Date ()));

as the API page

You can insert your own text into the pattern

"yyyy.MM.dd G 'at' HH:mm:ss z"  2001.07.04 AD at 12:08:56 PDT
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
-3

Try setting

DateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
java.util.Date date3 = new java.util.Date();
date3.setHours(0);
date3.setMinutes(0);
date3.setSeconds(0);
akash
  • 22,664
  • 11
  • 59
  • 87
AndyN
  • 1,742
  • 1
  • 15
  • 30