Fergusmac Fergusmac - 1 year ago 126
HTTP Question

Getting Date in HTTP format in Java

I'm trying to get a String of a date in Java in the format specified in HTTP 1.1. Which, as far as I can tell, is:

Fri, 31 Dec 1999 23:59:59 GMT

With the time always being GMT.

What would be the easiest way to get this from Date/Calendar/?

Answer Source

In case someone else will try to find the answer here (like I did) here's what will do the trick:

String getServerTime() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat dateFormat = new SimpleDateFormat(
        "EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
    return dateFormat.format(calendar.getTime());

in order to set the server to speak English and give time in GMT timezone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download