This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get current date at midnight?

 
Kellin Arbuckle
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an object of gregorian calender. You can create a date object using individual ints for the different month, day, ....
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic