This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
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.