If-Modified-Since Date Format

2019-02-13 01:51发布

I am now 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)....

Follwing is howi did 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 ..

2条回答
家丑人穷心不美
2楼-- · 2019-02-13 02:02

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.

查看更多
孤傲高冷的网名
3楼-- · 2019-02-13 02:07

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

long timeInMillis = ifModifiedSince.getTime();
查看更多
登录 后发表回答