HttpWebResponse.LastModified 屬性

定義

取得最近修改回應內容的日期和時間。

public:
 property DateTime LastModified { DateTime get(); };
public DateTime LastModified { get; }
member this.LastModified : DateTime
Public ReadOnly Property LastModified As DateTime

屬性值

DateTime,包含修改回應內容的日期和時間。

例外狀況

目前的執行個體已經過處置。

範例

此範例會 HttpWebRequest 建立 和 查詢回應。 此範例接著會檢查所要求的實體是否隨時都已修改。

Uri^ myUri = gcnew Uri( url );
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( myUri ) );
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
if ( myHttpWebResponse->StatusCode == HttpStatusCode::OK )
{
   Console::WriteLine( "\r\nRequest succeeded and the requested information is in the response , Description : {0}",
      myHttpWebResponse->StatusDescription );
}
DateTime today = DateTime::Now;
// Uses the LastModified property to compare with today's date.
if ( DateTime::Compare( today, myHttpWebResponse->LastModified ) == 0 )
{
   Console::WriteLine( "\nThe requested URI entity was modified today" );
}      
else if ( DateTime::Compare( today, myHttpWebResponse->LastModified ) == 1 )
{
   Console::WriteLine( "\nThe requested URI was last modified on: {0}",
      myHttpWebResponse->LastModified );
}
// Releases the resources of the response.
myHttpWebResponse->Close();
Uri myUri = new Uri(url);
    // Creates an HttpWebRequest for the specified URL.
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
    if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
        Console.WriteLine("\r\nRequest succeeded and the requested information is in the response , Description : {0}",
                            myHttpWebResponse.StatusDescription);
    DateTime today = DateTime.Now;
    // Uses the LastModified property to compare with today's date.
    if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 0)
        Console.WriteLine("\nThe requested URI entity was modified today");
    else
        if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 1)
            Console.WriteLine("\nThe requested URI was last modified on:{0}",
                                myHttpWebResponse.LastModified);
    // Releases the resources of the response.
    myHttpWebResponse.Close();
Dim myUri As New Uri(url)
' Creates an HttpWebRequest for the specified URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest)
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
    Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "Request succeeded and the requested information is in the response , Description : {0}", myHttpWebResponse.StatusDescription)
End If
Dim today As DateTime = DateTime.Now
' Uses the LastModified property to compare with today's date.
If DateTime.Compare(today, myHttpWebResponse.LastModified) = 0 Then
    Console.WriteLine(ControlChars.Cr + "The requested URI entity was modified today")
Else
    If DateTime.Compare(today, myHttpWebResponse.LastModified) =  1 Then
        Console.WriteLine(ControlChars.Cr + "The requested Uri was last modified on:{0}", myHttpWebResponse.LastModified)
    End If
End If
' Releases the resources of the response.
myHttpWebResponse.Close()

備註

屬性 LastModified 包含回應所收到的 Last-Modified 標頭值。 日期和時間假設為當地時間。

適用於