Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date format conversion

Status
Not open for further replies.

memphisTNdev22

Programmer
Joined
Jan 3, 2006
Messages
7
Location
US
Hey,

How may I be able to convert a date with the format of yyww with will be year and week, to a format of mmyy which will be month and year?

 
Code:
DateFormat df1 = new SimpleDateFormat("yyww");
DateFormat df2 = new SimpleDateFormat("MMyy");

//If your 'date' held in String var yourDate
//converted into String var mydate
String myDate = df2.format( df1.parse(yourDate) );

I don't know if this would work this simply. I haven't tried it, but it's got a reasonable chance.

(Oh, and you'll need to catch a ParseException from this code).

Tim
 
Notice on your locale of your system. I myself run JDK in Chinese system and i have to type chinese for the month.
If your locale uses English language, there is no problem
 
According to the API for SimpleDateFormat, it is locale-sensitive. Wouldn't it automatically cope with this, prosper?

Tim
 
I suspect, if it works at all, it'll consider the first day of the week as the date to convert. I know you don't like me assuming things, Stefan [smile], but I just gave a quick reply and hoped the poster would try it and respond with another question if it didn't work.

Tim
 
@timw: Don't I? :)
My question 'how can you convert ...' was meant for memphisTNdev22 in the first place...

Perhaps there is a official convention for such conversions - well known in some communities like attorneys or accountants.

seeking a job as java-programmer in Berlin:
 
Stefen said:
Perhaps there is a official convention for such conversions

Very possibly. Memphis, would you like to comment at some point?

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top