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

how to change the date format

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai guys i have a problem in changing the date format from , this is as follows

i will be getting a string "050622" which is taken as date format "yyMMdd" now thw thing is that we have to change the String to Date and the format of Date being "dd-MMM-yy".

i have tried with the following code but was stuck up at the point

public static void main(String[] args)
{
try
{
String srcValue = "050622";
ParsePosition pos = new ParsePosition(0);
SimpleDateFormat SDF=new SimpleDateFormat("yyMMdd");
Date dt = SDF.parse(srcValue,pos);
SDF.applyPattern("dd-MMM-yy");
srcValue = SDF.format(dt);
System.out.println(srcValue);

}
catch(Exception e)
{
System.out.println(e);
}

}
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
It seems to be working fine for me.. get '22-Jun-05' as output. What exactly is the error message you get?

Ravi
 
kiran mohan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ravi i did even got the same output but the thing is that the result is a string object but my client requires it in a date object. so i hope u got me
plz try and help out

bye
ThankYou
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

my client requires it in a date object.


Which you have as soon as you parse the initial String. What question do you have about that?

so i hope u got me
plz try and help out


Please make the extra effort to write out words such as "please" and "you". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.
 
Steve Morrow
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thw thing is that we have to change the String to Date and the format of Date being "dd-MMM-yy".

Be aware that Date objects don't have a format. They represent a point in time. The Date can be represented as a String, but the formatted representation is a String, not a Date.

Hope this helps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic