X509Certificate.GetExpirationDateString 方法

定義

傳回這個 X.509v3 憑證的到期日。Returns the expiration date of this X.509v3 certificate.

public:
 virtual System::String ^ GetExpirationDateString();
public virtual string GetExpirationDateString ();
abstract member GetExpirationDateString : unit -> string
override this.GetExpirationDateString : unit -> string
Public Overridable Function GetExpirationDateString () As String

傳回

String

這個 X.509 憑證的到期日。The expiration date for this X.509 certificate.

範例

下列範例 GetExpirationDateString 會使用方法來取得憑證的到期日,並將其顯示在主控台中。The following example uses the GetExpirationDateString method to get the expiration date of a certificate and displays it to the console.

using namespace System;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
   
   // The path to the certificate.
   String^ Certificate = "Certificate.cer";
   
   // Load the certificate into an X509Certificate object.
   X509Certificate^ cert = X509Certificate::CreateFromCertFile( Certificate );
   
   // Get the value.
   String^ results = cert->GetExpirationDateString();
   
   // Display the value to the console.
   Console::WriteLine( results );
}


using System;
using System.Security.Cryptography.X509Certificates;

public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate =  "Certificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

        // Get the value.
        string results = cert.GetExpirationDateString();

        // Display the value to the console.
        Console.WriteLine(results);
    }
}
Imports System.Security.Cryptography.X509Certificates




Public Class X509
   
   
   Public Shared Sub Main()
      
      ' The path to the certificate.
      Dim Certificate As String = "Certificate.cer"
      
      ' Load the certificate into an X509Certificate object.
      Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
      
      ' Get the value.
      Dim results As String = cert.GetExpirationDateString()
      
      ' Display the value to the console.
      Console.WriteLine(results)
   End Sub  
End Class 

備註

到期日是指不再將 x.509 憑證視為有效的日期。The expiration date is the date after which the X.509 certificate is no longer considered valid.

GetExpirationDateString方法會傳回字串,該字串會顯示在簡短日期模式中格式化的日期,後面接著格式化為完整時間模式的時間。The GetExpirationDateString method returns a string that shows the date formatted in Short Date Pattern followed by the time formatted in Long Time Pattern. 日期和時間會使用目前的文化特性和時區來格式化。The date and time are formatted using the current culture and time zone.

注意

此方法可能會在 Macintosh 電腦上傳回不同的字串格式,但基礎 DateTime 物件會代表相同的值。This method may return a different string format on Macintosh computers, although the underlying DateTime object will represent the same value.

適用於