• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problems handling the Date Class.

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answered in your other thread - https://coderanch.com/t/545894/Servlets/java/Problems-handling-Date-Class .
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic