Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

String to Date conversion very frustrating

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I want to a convert String sValid = "05/11/2003" to a date format in mm/dd/yyyy only.
When i am using the below mentioned code it is giving me week ate:time
which i dont want . I only want in mm/dd/yyyy format.
can Any one Help

/*
String string_date = "05/11/2003";
java.util.Date util_date;
SimpleDateFormat sdf = new SimpleDateFormat( "mm/dd/yyyy" );
util_date = sdf.parse( string_date );
System.out.println (util_date);
} catch (Exception e) {
System.out.println (e);
}
*/
Regards
Monzy
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are parsing a String into a java.util.Date object, then printing out the java.util.Date object. I think what you want to do is use SimpleDateFormat to format() a String into your chosen form, then print out that String.
And to head off the next question, check your pattern against the
documentation.
[ November 07, 2003: Message edited by: Joe Ess ]
 
MONZY THARIAN
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Thanks Joe for ur valuable time.
I do not want the output in String. I want the output in Date object only in mm/dd/yyyy.
JAVA GURUS Is it possible to get a Date object only in mm/dd/yyyy format without Time.

Regards
Monzy
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAVA GURUS Is it possible to get a Date object only in mm/dd/yyyy format without Time.
I'd say that Joe is a Java guru. And his last advice is still important here - check the format pattern you're using against the documentation. Specifically, what do m, d, and y mean? There's a subtle flaw in your current pattern.
Now that thing is, a Date will always have a time component to it. If you set up your pattern correctly to parse a date using only may, month, and year, then the time should compe out equal to 00:00:00. If you don't care about time, then just ignore the 00:00:00. If you don't want to see it, then don't print out your Date without using a formatter, as Joe suggested:

Hope that helps...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic