File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Date Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date Format" Watch "Date Format" New topic

Date Format

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Here is part of my code for date:
Date today=new Date();
submittedDate = today.toString();
Result is: Mon Dec 10 14:05:54 PST 2001
Question: how can I change the format to have date like this 2001-12-05
Please help.

Steve Campbell
Ranch Hand

Joined: Dec 18, 2000
Posts: 41
Check out the SimpleDateFormat class.
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Hi all,
SubmittedDate in my database is like this and I defined it as a string "Wed Dec 12 12:08:56 PST 2001"
but I don't know why I couldn't get output I mean when I wanted to print it nothing pass but the otherside I don't have any problem to pass and print FixedDate which is like this
Please help.
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
The SimpleDateFormat class allows you to choose among several formats for Date objects. Good Luck!

Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="" target="_blank" rel="nofollow"></a>
Matt O'Keefe

Joined: Nov 28, 2000
Posts: 7
You should always use the Calendar class so that you can deal with timezones properly. With that in mind, try something like this:
Calendar now = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String nowStr = format.format(now.getTime());
You can also do other cool stuff like parse a string to create a Date.
I agree. Here's the link:
subject: Date Format
It's not a secret anymore!