• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Remove time part from java.util.Date()

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to get only the date part of java.util.Date() resetting time to 00.

Let me make it more clear. When I am initializing the date object as

java.util.Date date = new java.util.Date();

I am getting the date object with value as "Thu May 27 12:13:49 IST 2010"
I just want to set the time part of this object to "00:00:00"
I dont want to get the output as String using DateFormat class.
The output should be a java.util.Date object only.

In java.util.Date, setHours, setMinutes and setSeconds functions are deprecated.
What alternative I can use instead of those function?

Can anyone please help me for this?

# Subject edited
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mahesh Kedari wrote:In java.util.Date, setHours, setMinutes and setSeconds functions are deprecated.
What alternative I can use instead of those function?


The answer is in the Date class API. Can you find it ?
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might be helpful to realize that java.util.Date is essentially nothing more than a wrapper for a long value that represents the milliseconds that have passed since January 1st 1970.
Formatting that long value as a human readable String is no longer its responsibility. If you look at the documentation of some of its deprecated methods that used to offer this kind of behaviour (toGMTString() / toLocaleString()), you'll find that DateFormat should indeed be used for this purpose. What's your reason for not wanting to use the DateFormat class?

Edit: Oh, nevermind, I misunderstood your question.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the Calendar class, which is much more flexible than the Date class:

 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic