Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If-Modified-Since Date Format

I am writing a server and I would like to check for "If-Modified-Since: " header.
Since there are so many date methods, which methods should I consider to check, like a usual method (milliseconds is used in browsers)....

Following is how I did it for milliseconds format:

  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 for "Wed, 19 Oct 2005 10:50:00 GMT" format. How can I change that date into 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 chaging the above and please tell me if there is any Date format that I should check for…

like image 648
Ken Avatar asked Nov 27 '12 21:11

Ken


People also ask

What does if-modified-since mean?

The If-Modified-Since request HTTP header makes the request conditional: the server sends back the requested resource, with a 200 status, only if it has been last modified after the given date.

What is the purpose for the if-modified-since header?

The If-Modified-Since HTTP header indicates the time for which a browser first downloaded a resource from the server. This helps determine whether or not the resource has changed since the last time it was accessed.

What are the If-modified-since and if-none-match header used for?

The If-Modified-Since header is used to specify the time at which the browser last received the requested resource. The If-None-Match header is used to specify the entity tag that the server issued with the requested resource when it was last received.

What HTTP status code means that the requested file was found but has not changed since date provided in the IF-modified-since header?

If the client has done a conditional GET and access is allowed, but the document has not been modified since the date and time specified in If-Modified-Since field, the server responds with a 304 status code and does not send the document body to the client.


2 Answers

HTTP applications have historically allowed three different formats for the representation of 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's asctime() format

More details in HTTP/1.1 RFC 2616.

like image 82
MannVoo Avatar answered Sep 30 '22 13:09

MannVoo


As you already have the Date object, you can use:

long timeInMillis = ifModifiedSince.getTime();
like image 27
Reimeus Avatar answered Sep 30 '22 13:09

Reimeus