-3

I have this date format that i would like to generate using the Calendar class in Java

Date : Thu, 04 Jun 2009 02:51:59 GMT

What's the best way to generate it ?

Thanks in advance

hshihab
  • 416
  • 5
  • 16
  • 5
    show some efforts first – Prasad Kharkar Aug 26 '13 at 11:52
  • Tip: Search Stack Overflow for java.time classes, specifically [`OffsetDateTime`](https://docs.oracle.com/javase/10/docs/api/java/time/OffsetDateTime.html) and [`DateTimeFormatter.RFC_1123_DATE_TIME`](https://docs.oracle.com/javase/10/docs/api/java/time/format/DateTimeFormatter.html#RFC_1123_DATE_TIME). – Basil Bourque Aug 31 '18 at 04:52
  • Duplicate of: [Getting Date in HTTP format in Java](https://stackoverflow.com/q/7707555/642706). – Basil Bourque Aug 31 '18 at 04:54

1 Answers1

3

Use the SimpleDateFormat class. Calendar doesn't format dates.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52
  • FYI, the terribly troublesome old date-time classes such as [`java.util.Date`](https://docs.oracle.com/javase/10/docs/api/java/util/Date.html), [`java.util.Calendar`](https://docs.oracle.com/javase/10/docs/api/java/util/Calendar.html), and `java.text.SimpleDateFormat` are now [legacy](https://en.wikipedia.org/wiki/Legacy_system), supplanted by the [*java.time*](https://docs.oracle.com/javase/10/docs/api/java/time/package-summary.html) classes built into Java 8 and later. See [*Tutorial* by Oracle](https://docs.oracle.com/javase/tutorial/datetime/TOC.html). – Basil Bourque Aug 31 '18 at 04:50