This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes SimpleDateFormat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "SimpleDateFormat" Watch "SimpleDateFormat" New topic


Janne ukko

Joined: Nov 25, 2004
Posts: 10
Hello need some help !

i take in a String that looks like timePattern

I just wonder how i change the output format when converting this

if i make a print out on the result now i got Thu Nov 25 00:00:00 CET 2004
if i want for example 2004-11-30 12:33:35 how do i do that.

String timePattern = "yyyy-MM-dd";
SimpleDateFormat formatter = new SimpleDateFormat(timePattern);

Date fe=getDateInstance(formatter);

Date d = null;
try {
d = formatter.parse(publishDate, new ParsePosition(0));
} catch (NullPointerException e) {
System.out.print(d) // gives Thu Nov 25 00:00:00 CET 2004
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
SimpleDateFormat has output functions as well as input functions.

check the API docs... it's what they're there fore, learn to use them.

Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9058
Here is an explanation of how to use SimpleDateFormat.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: SimpleDateFormat
It's not a secret anymore!