aspose file tools
The moose likes Beginning Java and the fly likes Get current date at midnight? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Get current date at midnight?" Watch "Get current date at midnight?" New topic
Author

Get current date at midnight?

Kellin Arbuckle
Greenhorn

Joined: Jul 06, 2004
Posts: 1
How can I set a variable equal to the current date with the time set to midnight?

In other words, each time my program runs, I want:

myDate = MM/dd/yyyy 00:00:00

Where MM/dd/yyyy is the current date.
Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
Create an object of gregorian calender. You can create a date object using individual ints for the different month, day, ....


Jeremy Wilson
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Hi Kent,

Jeremy had already given you the clue to get started.

Since you need the current date, your best bet would be the system date, that will always give you today's (current) date.

Using the java.util.GregorianCalendar class, you're able to get this current date. Hint: look at its constructor.

Your second part involves setting your time components, namely HOUR, MINUTE & SECOND into 0s. So there must be some way (methods) that can help you to do the setting jobs.

The API for GregorianCalendar will be able to help you get all the pieces together into your desired codes.

HTH.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Get current date at midnight?
 
Similar Threads
Insert a row into MS Access2003 successfully,But the long date(YYYY/MM/DD HH:mm:ss) was changed
Date comparision in SQL from timestamp
Trying to see if incoming date parameter has a time attached or not (wwithout using midnight)
how to change the date,Time format after accessing it from the database
String to Date conversion very frustrating