If-Modified-Date Date Format

Now I am writing a server, and I would like to check the "If-Modified-Since:" header.
Since there are so many date methods, which methods should be considered, for example, as a regular method (milliseconds are used in browsers) ....

Follwing has a format for milliseconds.

Date date; //dateS is a substring of If-Modified-Since: header try{ long mills = Long.parseLong(dateS); } catch (NumberFormatException e) {e.printStackTrace(); } date = new Date(mills); 

I also want to check the format "Wed, 19 Oct 2005 10:50:00 GMT". How can I change this date in milliseconds?

  SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss z"); // to check if-modified-since time is in the above format try { ifModifiedSince = dateFormat.parse(date); ????????????????????? } catch (ParseException e1) { } 

Please help me with the listening above and please tell me if there is a date format that I should check.

+7
source share
2 answers

HTTP applications have historically allowed three different formats for representing date / time stamps:

 Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C asctime() format 

See details in HTTP / 1.1 RFC 2616 .

+14
source

Since you already have a Date object, you can use:

 long timeInMillis = ifModifiedSince.getTime(); 
+1
source

All Articles