This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes  calendar.setTime(date) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " calendar.setTime(date)" Watch " calendar.setTime(date)" New topic
Author

calendar.setTime(date)

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hi all, I want to get the hour of day in 24hour cycle. I know that date.getHours() is depreciated. But I'm tempted to use it since I can not get the same result out of calendar.hour call.
It seems call calendar.setTime(now) does not pick up the current date value. Anybody knows what's going on here? I have the following:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Values such as c.HOUR do not return the hour of the date. They are constants used with the API to identify date fields.

Consider: c.get(Calendar.HOUR)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I cant tell you how thankful I am! Thanks so much!
Abdul Aatif
Greenhorn

Joined: Feb 08, 2012
Posts: 23
Bear Bibeault wrote:Values such as c.HOUR do not return the hour of the date. They are constants used with the API to identify date fields.

Consider: c.get(Calendar.HOUR)


Thank you so much.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: calendar.setTime(date)
 
Similar Threads
Adding three weeks to a date
Date calculation
Create an Array of Weeks
java.sql.Date to java.util.Calendar
Bug in java.util.Date.toString():?