共用方式為


X509Certificate.GetExpirationDateString 方法

定義

傳回這個 X.509v3 憑證的到期日。

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 憑證的到期日。

範例

下列範例會 GetExpirationDateString 使用 方法來取得憑證的到期日,並將其顯示至主控台。

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 憑證不再被視為有效的日期。

方法 GetExpirationDateString 會傳回字串,顯示以簡短日期模式格式化的日期,後面接著以長時間模式格式化的時間。 日期和時間是使用目前的文化特性和時區來格式化。

注意

這個方法可能會在Macintosh電腦上傳回不同的字串格式,不過基礎 DateTime 物件會代表相同的值。

適用於