• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Date Format

 
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the SimpleDateFormat class.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SimpleDateFormat class allows you to choose among several formats for Date objects. Good Luck!
-Jason
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!