datetime formatting

Posted on 2006-04-08
Medium Priority
Last Modified: 2010-03-31
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.
Question by:DaFou
  • 2
  • 2
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 16410439
                 DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz");
                  System.out.println(df.format(new java.util.Date()));
LVL 14

Expert Comment

by:Tommy Braas
ID: 16410534
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);
LVL 14

Expert Comment

by:Tommy Braas
ID: 16410538
To then ge the Date object needed by the DateFormat you need to call:
Date date = calendar.getTime();
LVL 86

Expert Comment

ID: 16411203

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question