System.Security.Cryptography.X509Certificates.X509Certificate.FormatDate C# (CSharp) Method

FormatDate() protected static method

Convert a date to a string. Some cultures, specifically using the Um-AlQura calendar cannot convert dates far into the future into strings. If the expiration date of an X.509 certificate is beyond the range of one of these cases, we need to fall back to a calendar which can express the dates
protected static FormatDate ( System.DateTime date ) : string
date System.DateTime
return string
        protected static string FormatDate(DateTime date)
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            if (!culture.DateTimeFormat.Calendar.IsValidDay(date.Year, date.Month, date.Day, 0))
            {
                // The most common case of culture failing to work is in the Um-AlQuara calendar. In this case,
                // we can fall back to the Hijri calendar, otherwise fall back to the invariant culture.
                if (culture.DateTimeFormat.Calendar is UmAlQuraCalendar)
                {
                    culture = culture.Clone() as CultureInfo;
                    culture.DateTimeFormat.Calendar = new HijriCalendar();
                }
                else
                {
                    culture = CultureInfo.InvariantCulture;
                }
            }

            return date.ToString(culture);
        }

Same methods

X509Certificate::FormatDate ( System date ) : string

Usage Example

Exemplo n.º 1
0
        public virtual string ToString(bool fVerbose)
        {
            if (!fVerbose || this.m_safeCertContext.IsInvalid)
            {
                return(this.GetType().FullName);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("[Subject]" + Environment.NewLine + "  ");
            stringBuilder.Append(this.Subject);
            stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Issuer]" + Environment.NewLine + "  ");
            stringBuilder.Append(this.Issuer);
            stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Serial Number]" + Environment.NewLine + "  ");
            stringBuilder.Append(this.SerialNumber);
            stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Not Before]" + Environment.NewLine + "  ");
            stringBuilder.Append(X509Certificate.FormatDate(this.NotBefore));
            stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Not After]" + Environment.NewLine + "  ");
            stringBuilder.Append(X509Certificate.FormatDate(this.NotAfter));
            stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Thumbprint]" + Environment.NewLine + "  ");
            stringBuilder.Append(this.GetCertHashString());
            stringBuilder.Append(Environment.NewLine);
            return(stringBuilder.ToString());
        }
All Usage Examples Of System.Security.Cryptography.X509Certificates.X509Certificate::FormatDate