If-Modified-Since日期格式 [英] If-Modified-Since Date Format

查看:703
本文介绍了If-Modified-Since日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个服务器,我想检查If-Modified-Since:标题。

由于有这么多日期方法,我应该考虑哪些方法来检查,例如通常的方法(浏览器中使用毫秒)....



Follwing是以毫秒为单位的格式。

 日期日期; 

// dateS是If-Modified-Since的子字符串:header
try {
long mills = Long.parseLong(dateS);
} catch(NumberFormatException e)
{e.printStackTrace();
}
date = new Date(mills);

我也想检查Wed,19 Oct 2005 10:50:00 GMT格式。如何将该日期更改为毫秒?

  SimpleDateFormat dateFormat = new SimpleDateFormat(
EEE,dd MMM yyyy HH:mm:ss z);

//检查是否修改,因为时间是上述格式
try {

ifModifiedSince = dateFormat.parse(date);
??
} catch(ParseException e1){
}

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

解决方案

HTTP应用程序历来允许三日期/时间戳的不同格式:

  Sun,06 Nov 1994 08:49:37 GMT; RFC 822,由RFC 1123更新
星期日,06-Nov-94 08:49:37 GMT; RFC 850,被RFC 1036废弃了
Sun Nov 6 08:49:37 1994; ANSI C的asctime()格式

HTTP / 1.1 RFC中的更多详细信息 2616


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 ..

解决方案

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.

这篇关于If-Modified-Since日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆