2012-11-27 62 views
7

我現在正在編寫一個服務器,我想檢查「If-Modified-Since:」標題。
既然有這麼多的日期的方法,這方法我應該考慮檢查一下,像通常的方法(毫秒在瀏覽器中使用的)....If-Modified-Since Date Format

Follwing是howi沒有爲毫秒格式。

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); 

我也想檢查 「星期三,2005年10月19日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) { 
     } 

請幫我換款以上並請告訴我,如果有任何日期格式,我應該檢查..

+0

已經回答了,我相信: [http://stackoverflow.com/questions/1930158/how-to-parse-date-from-http-last-modified-header][1] [1]:http://stackoverflow.com/questions/1930158/how-to-parse-date-from-http-last-modified-header – Farid

+0

瀏覽器使用毫秒作爲Last-Modified-Date,因爲這是我的已在所有瀏覽器 – Ken

+0

請求標題中我指的是使用format.parse(dateString).getTime(); – Farid

回答

1

正如你已經有Date對象,你可以使用:

long timeInMillis = ifModifiedSince.getTime(); 
14
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 

HTTP/1.1 RFC 2616中的更多細節。