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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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://aspose.com/file-tools
 
subject: Get current date at midnight?