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 对象将表示相同的值。

适用于