Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

how to change the date format  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • 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
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Let's get him boys! We'll make him read this tiny ad!
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!