Seymour Cakes Seymour Cakes - 2 years ago 83
Java Question

Is there an easier way to get start of current day time than this?

I basically want to get zero or beginning hour for currrent day.

def today = Calendar.instance
today.set(Calendar.HOUR_OF_DAY, 0)
today.set(Calendar.MINUTE, 0)
today.set(Calendar.SECOND, 0)
println today // Mon Mar 15 00:00:00 SGT 2010

Answer Source

Not simpler than the other solutions, but less lines:

def now = new GregorianCalendar()
def today = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH))
println today.getTime()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download