If-Modified-Since日期格式

Ken*_*Ken 9 java date date-format

我现在正在写一个服务器,我想检查"If-Modified-Since:"标题.
由于有太多的日期方法,我应该考虑检查哪种方法,就像通常的方法(浏览器中使用毫秒)....

Follwing是毫秒格式的.

  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);
Run Code Online (Sandbox Code Playgroud)

我还要检查"Wed,19 Oct 10:50:00 GMT"格式.如何将该日期更改为毫秒?

     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) {
        }
Run Code Online (Sandbox Code Playgroud)

请帮我处理以上问题,请告诉我是否有任何日期格式我应该检查..

小智 18

历史上,HTTP应用程序允许使用三种不同的格式来表示日期/时间戳:

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
Run Code Online (Sandbox Code Playgroud)

HTTP/1.1 RFC 2616中的更多细节.


Rei*_*eus 1

由于您已经拥有该Date对象,因此可以使用:

long timeInMillis = ifModifiedSince.getTime();
Run Code Online (Sandbox Code Playgroud)