System.Xml.Xsl.Runtime.XsltFunctions.MSFormatDateTime C# (CSharp) Method

MSFormatDateTime() public static method

public static MSFormatDateTime ( string dateTime, string format, string lang, bool isDate ) : string
dateTime string
format string
lang string
isDate bool
return string
        public static string MSFormatDateTime(string dateTime, string format, string lang, bool isDate)
        {
            try
            {
                string locale = GetCultureInfo(lang).Name;

                XsdDateTime xdt;
                if (!XsdDateTime.TryParse(dateTime, XsdDateTimeFlags.AllXsd | XsdDateTimeFlags.XdrDateTime | XsdDateTimeFlags.XdrTimeNoTz, out xdt))
                {
                    return string.Empty;
                }
                DateTime dt = xdt.ToZulu();

                // If format is the empty string or not specified, use the default format for the given locale
                if (format.Length == 0)
                {
                    format = null;
                }
                return dt.ToString(format, new CultureInfo(locale));
            }
            catch (ArgumentException)
            { // Operations with DateTime can throw this exception eventualy
                return string.Empty;
            }
        }