wood burning stoves*
The moose likes Java in General and the fly likes  Problems handling the Date Class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark " Problems handling the Date Class." Watch " Problems handling the Date Class." New topic
Author

Problems handling the Date Class.

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi all,
I had a doubt while trying to manipulate the Date class.I'm retreiving values from the database that are of the form "dd-MMM-yyyy" e.g 06-Jun-2011 .The problem causing code is as below
.

Any idea on how I could convert the value in dtVar to the same as that of strdateVar??As the value of dtVar needs to be set into a bean of return type Date.
Thank you for your time.


Learning and Learning!-- Java all the way!
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Answered in your other thread - http://www.coderanch.com/t/545894/Servlets/java/Problems-handling-Date-Class .


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

James Sabre wrote:Use a second SimpleDateFormat with formatting argument that reflects to format you desired then format dtVar as a String.

Note - if you are going to do any date type comparisons you will normally do better to compare java.util.Date objects than String objects.

uh I didnt quite get you .Can you please explain in code the point of using a second SimpleDateFormat instance?
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Vic Hood wrote:Any idea on how I could convert the value in dtVar to the same as that of strdateVar??As the value of dtVar needs to be set into a bean of return type Date.


dtVar and strdateVar have the same values. Its just the representation that is different.

As dtVar is a Date object, you can use it directly to set the values of the bean property.
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Sridhar Santhanakrishnan wrote:
Vic Hood wrote:Any idea on how I could convert the value in dtVar to the same as that of strdateVar??As the value of dtVar needs to be set into a bean of return type Date.


dtVar and strdateVar have the same values. Its just the representation that is different.

As dtVar is a Date object, you can use it directly to set the values of the bean property.

yes ,Sure if it had the right value , if you read my post correctly ..
the value of strdateVar is --06-Jun-2011
The value of dtVar is of the form --Mon Jun 06 00:00:00 IST 2011
So you see I cant use it??
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

I really don't understand what you are trying to do! java.utl.Date objects store the date as the number of millisecoonds since 1/1/1970 00:00:00 UTC. The value you get from the toString() method is just a human readable form of the date and does not in any way reflect how the data is stored in the java.util.Date.

What are you trying to do?
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Vic Hood wrote:
yes ,Sure if it had the right value , if you read my post correctly ..
the value of strdateVar is --06-Jun-2011
The value of dtVar is of the form --Mon Jun 06 00:00:00 IST 2011
So you see I cant use it??


I dont see how they are different. 06-Jun-2011 and Mon Jun 06 00:00:00 IST 2011 both mean the 6th of June, 2011. Run the below snippet and see the output.



dtVar, like James mentioned, contains the value that you want as a Date object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems handling the Date Class.
 
Similar Threads
How to change Date Format
SimpleDateFormat not returning expectec output?
Help for using Java Time
Can someone please help me parse this date
Convert String to Date Issue