Пример #1
0
        ///<include file='doc\XmlConvert.uex' path='docs/doc[@for="XmlConvert.ToDateTime3"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static DateTime ToDateTime(string s, XmlDateTimeSerializationMode dateTimeOption)
        {
            XsdDateTime xsdDateTime = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
            DateTime    dt          = (DateTime)xsdDateTime;

            switch (dateTimeOption)
            {
            case XmlDateTimeSerializationMode.Local:
                dt = SwitchToLocalTime(dt);
                break;

            case XmlDateTimeSerializationMode.Utc:
                dt = SwitchToUtcTime(dt);
                break;

            case XmlDateTimeSerializationMode.Unspecified:
                dt = new DateTime(dt.Ticks, DateTimeKind.Unspecified);
                break;

            case XmlDateTimeSerializationMode.RoundtripKind:
                break;

            default:
                throw new ArgumentException(SR.Format(SR.Sch_InvalidDateTimeOption, dateTimeOption, "dateTimeOption"));
            }
            return(dt);
        }
Пример #2
0
        ///<include file='doc\XmlConvert.uex' path='docs/doc[@for="XmlConvert.ToString14"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static string ToString(DateTime value, XmlDateTimeSerializationMode dateTimeOption)
        {
            switch (dateTimeOption)
            {
            case XmlDateTimeSerializationMode.Local:
                value = SwitchToLocalTime(value);
                break;

            case XmlDateTimeSerializationMode.Utc:
                value = SwitchToUtcTime(value);
                break;

            case XmlDateTimeSerializationMode.Unspecified:
                value = new DateTime(value.Ticks, DateTimeKind.Unspecified);
                break;

            case XmlDateTimeSerializationMode.RoundtripKind:
                break;

            default:
                throw new ArgumentException(SR.Format(SR.Sch_InvalidDateTimeOption, dateTimeOption, "dateTimeOption"));
            }
            XsdDateTime xsdDateTime = new XsdDateTime(value, XsdDateTimeFlags.DateTime);

            return(xsdDateTime.ToString());
        }
Пример #3
0
        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);
        }
Пример #4
0
        public static string ToString(DateTimeOffset value)
        {
            XsdDateTime xsdDateTime = new XsdDateTime(value);

            return(xsdDateTime.ToString());
        }