Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java Date formatting problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From a jsp i submit a date object .In the java code i am getting the date object in this format Wed Dec 03 00:00:00 GMT+05:30 2008.But I need the date object in this format 03-Dec-08.
What i have done so far -----
Date date=getDateOfTransaction(); // Get the date obj from the form
DateFormat dtformat=new SimpleDateFormat("dd-MMM-yy");
String trandate= dtformat.format(date); // In the string output 03-Dec-08
Date dt=(Date)dtformat.parse(trandate); //output of dt Wed Dec 03
00:00:00 GMT+05:30 2008


How can i get only this thing (03-Dec-08) in the date object....
 
Marshal
Posts: 74632
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somebody else has a similar problem: look here.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused. You said you wanted a value like "03-Dec-08", and the code comment indicates that "trandate" has exactly that value. What else are you looking for?

Keep in mind that Date objects have no formatting. You can get any number of formatted string representations in the way you did, but that doesn't change the Date object itself.
 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get the date object in the 03-Dec-08 format.....Is it possible?
 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually this date object is the search criteria .I am using oracle database .In the database the way it is stored is 03-Dec-08.So for matching
the date i have to send the date object in the database in this way 03-Dec-08. As it is not matching so the criteria is not satisfied . I am using hibernet query

"from MasterData masterData where masterData.dateOfTransaction like '"+localDate+"'");

Is there another way....then please tell me....
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


you can probably try using



And I wonder why you are using like to compare Date Objects. equals(=) should be sufficient.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kaushik saha:
I want to get the date object in the 03-Dec-08 format.....Is it possible?


As I said in my previous post - Date objects have no formatting. You can obtain string representations of Date objects that do have a formatting, and the code you posted before does exactly that. So I'd say you're looking for something that does not exist (and which you don't need anyway, because you already have what you said you needed).
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic