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

傳回

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

適用於