2012-11-27 13 views
7

Ora sto scrivendo un server e vorrei verificare l'intestazione "If-Modified-Since:".
Poiché ci sono tanti metodi di data, quali metodi dovrei prendere in considerazione per verificare, come un metodo usuale (millisecondi è utilizzato nei browser) ....Se modificato - Dal formato data

follwing è howi ha fatto per il formato millisecondi.

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

Desidero anche controllare il formato "Mer, 19 Ott 2005 10:50:00 GMT". Come posso cambiare quella data in millisecondi ??

 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 con chaging quanto sopra e la prego di dirmi se c'è qualche formato di data che dovrei controllare ..

+0

già risposto credo: [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

i browser utilizzano millisecondo come Data ultima modifica, perché è quello che ho state ricevendo nell'intestazione della richiesta in tutti i browser – Ken

+0

nel collegamento mi riferivo ad usare format.parse (dateString) .getTime(); – Farid

risposta

1

Come avete già l'oggetto Date, è possibile utilizzare:

long timeInMillis = ifModifiedSince.getTime(); 
14

applicazioni HTTP, storicamente, hanno permesso di tre diversi formati per la rappresentazione di data/ora:

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 

Ulteriori dettagli in HTTP/1.1 RFC 2616.