wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date Format" Watch "Date Format" New topic
Author

Date Format

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Hi,
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.
Thanks,
Elham


Thanks,
Elahe
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
"2001-12-05".
Please help.
Thanks,
Elaheh
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


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

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");
format.setCalendar(now);
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: http://aspose.com/file-tools
 
subject: Date Format
 
Similar Threads
date format problem
String to date conv
locale and style
date in UTC format
conversion from Date ojbect to Date object