• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date Format

 
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the SimpleDateFormat class.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic