File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems handling the Date Class.

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answered in your other thread - http://www.coderanch.com/t/545894/Servlets/java/Problems-handling-Date-Class .
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic