datetime formatting

Hi guys,

How do I create a datetime that looks like this:
Wed, 9 jan 2004 19:59:09 GMT

into a string?

The date should reflect the current date time on which it was created.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

                 DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz");
                  System.out.println(df.format(new java.util.Date()));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tommy BraasCommented:
You would have to create a Calendar object with the right time, and then use CEHJ's code to output it into the format requested:
// the time in your code
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR 2004);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.DAY_OF_MONTH 9);
calendar.set(Calendar.HOUR_OF_DAY, 19);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 9);
Tommy BraasCommented:
To then ge the Date object needed by the DateFormat you need to call:
Date date = calendar.getTime();
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.