System.Xml.XmlConvert.ToDateTimeOffset C# (CSharp) Méthode

ToDateTimeOffset() public static méthode

public static ToDateTimeOffset ( string s ) : DateTimeOffset
s string
Résultat DateTimeOffset
        public static DateTimeOffset ToDateTimeOffset(string s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            XsdDateTime xsdDateTime = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
            DateTimeOffset dateTimeOffset = (DateTimeOffset)xsdDateTime;
            return dateTimeOffset;
        }

Same methods

XmlConvert::ToDateTimeOffset ( string s, string format ) : DateTimeOffset

Usage Example

Exemple #1
0
        private object ValueAs(string text, Type type, IXmlNamespaceResolver resolver, bool isArrayItem)
        {
            try {
                if (type == typeof(object))
                {
                    return(text);
                }
                if (type.IsArray && !isArrayItem)
                {
                    var elemType = type.GetElementType();
                    var sarr     = text.Split((string [])null, StringSplitOptions.RemoveEmptyEntries);
                    var ret      = Array.CreateInstance(elemType, sarr.Length);
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret.SetValue(ValueAs(sarr [i], elemType, resolver, true), i);
                    }
                    return(ret);
                }

                if (type == typeof(XmlQualifiedName))
                {
                    if (resolver != null)
                    {
                        return(XmlQualifiedName.Parse(text, resolver, true));
                    }
                    else
                    {
                        return(XmlQualifiedName.Parse(text, this, true));
                    }
                }
                if (type == typeof(Uri))
                {
                    return(XmlConvert.ToUri(text));
                }
                if (type == typeof(TimeSpan))
                {
                    return(XmlConvert.ToTimeSpan(text));
                }
                if (type == typeof(DateTimeOffset))
                {
                    return(XmlConvert.ToDateTimeOffset(text));
                }

                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Boolean:
                    return(XQueryConvert.StringToBoolean(text));

                case TypeCode.DateTime:
                    return(XQueryConvert.StringToDateTime(text));

                case TypeCode.Decimal:
                    return(XQueryConvert.StringToDecimal(text));

                case TypeCode.Double:
                    return(XQueryConvert.StringToDouble(text));

                case TypeCode.Int32:
                    return(XQueryConvert.StringToInt(text));

                case TypeCode.Int64:
                    return(XQueryConvert.StringToInteger(text));

                case TypeCode.Single:
                    return(XQueryConvert.StringToFloat(text));

                case TypeCode.String:
                    return(text);
                }
            } catch (Exception ex) {
                throw XmlError(String.Format("Current text value '{0}' is not acceptable for specified type '{1}'. {2}", text, type, ex != null ? ex.Message : String.Empty), ex);
            }
            throw new ArgumentException(String.Format("Specified type '{0}' is not supported.", type));
        }