• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get current date at midnight?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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, ....
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic