The Artima Developer Community
Sponsored Link

Java Answers Forum
Converting/formatting a date

2 replies on 1 page. Most recent reply: Jun 20, 2006 4:24 PM by Nate Tompkins

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Nate Tompkins

Posts: 2
Nickname: technoman
Registered: Jun, 2006

Converting/formatting a date Posted: Jun 19, 2006 5:05 PM
Reply to this message Reply
Advertisement
I'm kind of new to Java. I'm using a report writer which is based on Java. I have a java.util.Date parameter that prompts the user for a date. The user types in 01/05/2004, but it gets stored as: Mon Jan 05 00:00:00 CST 2004. I have no control over that. Is there any way that I can convert or format that to the format: mm/dd/yyyy and store that into another variable so it contains 01/05/2004? Do I do something like this?:
new SimpleDateFormat("mm/dd/yyyy").parse(Entered_Date.toString()


Thanks.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Converting/formatting a date Posted: Jun 19, 2006 10:52 PM
Reply to this message Reply
It doesn't even get stored the way you mentioned, that's just the standard String output.

Use the class java.text.DateFormat to format your date.
Create a new instance of this class, set the format you like, then use the format(Date) method to get your String representation.

Nate Tompkins

Posts: 2
Nickname: technoman
Registered: Jun, 2006

Re: Converting/formatting a date Posted: Jun 20, 2006 4:24 PM
Reply to this message Reply
That's what I don't understand. I've looked at the API for java.text.DateFormat, but can't see how to format the date into MM/dd/yyyy.

Flat View: This topic has 2 replies on 1 page
Topic: Getting ip address of windows network Previous Topic   Next Topic Topic: Type mismatch error.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use