Umair A.
Umair A.

Reputation: 6863

Android Date and Time Format

I have a sample date format Tue, 23 Aug 2011 18:33:43 +0000

In Android, I am using this statement String now = new Date().toGMTString();

And I am receiving this 23 Aug 2011 18:03:25 GMT

What I need to do to get this format Tue, 23 Aug 2011 18:33:43 +0000?

Upvotes: 3

Views: 7573

Answers (3)

Joel F
Joel F

Reputation: 2631

Follow @MByD, except try this:

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT");
String formattedDate = dateFormat.format(yourDateInstance);

Upvotes: 1

MByD
MByD

Reputation: 137272

Use SimpleDateFormat.

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
String formattedDate = dateFormat.format(yourDateInstance);

Upvotes: 4

Dan S
Dan S

Reputation: 9189

You can use SimpleDateFormat to parse and format dates.

Upvotes: 4

Related Questions