This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes date to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "date to string" Watch "date to string" New topic
Author

date to string

Janardan Kelkar
Ranch Hand

Joined: May 05, 2008
Posts: 72

how do i get the current system date, and convert it to string, example, i want to generate the following string:
"28/08/2008"

i tried using calendar class and all, but have not been able to still figure it out properly..


When the compiler's not happy, ain't nobody happy.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
At least two ways to do it:
  • You can use the SimpleDateFormat class or similar and use that to format the output.
  • Use the tags of the Formatter class, which reappear in several locations
  • Example of the latter: String.format("%Td/%<TB/%<Ty", myDate) which won't give the format you are asking about.
    Janardan Kelkar
    Ranch Hand

    Joined: May 05, 2008
    Posts: 72

    k....thanks
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38441
        
      23
    You're welcome
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: date to string