System.Xml.Schema.XsdDateTime.ToString C# (CSharp) Méthode

ToString() public méthode

Serialization to a string
public ToString ( ) : string
Résultat string
        public override string ToString() {
            StringBuilder sb = new StringBuilder(64);
            char[] text;
            switch (InternalTypeCode) {
            case DateTimeTypeCode.DateTime:
                PrintDate(sb);
                sb.Append('T');
                PrintTime(sb);
                break;
            case DateTimeTypeCode.Time:
                PrintTime(sb);
                break;
            case DateTimeTypeCode.Date:
                PrintDate(sb);
                break;
            case DateTimeTypeCode.GYearMonth:
                text = new char[Lzyyyy_MM];
                IntToCharArray(text, 0, Year, 4);
                text[Lzyyyy] = '-';
                ShortToCharArray(text, Lzyyyy_, Month);
                sb.Append(text);
                break;
            case DateTimeTypeCode.GYear:
                text = new char[Lzyyyy];
                IntToCharArray(text, 0, Year, 4);
                sb.Append(text);
                break;
            case DateTimeTypeCode.GMonthDay:
                text = new char[Lz__mm_dd];
                text[0] = '-';
                text[Lz_] = '-';
                ShortToCharArray(text, Lz__, Month);
                text[Lz__mm] = '-';
                ShortToCharArray(text, Lz__mm_, Day);
                sb.Append(text);
                break;
            case DateTimeTypeCode.GDay:
                text = new char[Lz___dd];
                text[0] = '-';
                text[Lz_] = '-';
                text[Lz__] = '-';
                ShortToCharArray(text, Lz___, Day);
                sb.Append(text);
                break;
            case DateTimeTypeCode.GMonth:
                text = new char[Lz__mm__];
                text[0] = '-';
                text[Lz_] = '-';
                ShortToCharArray(text, Lz__, Month);
                text[Lz__mm] = '-';
                text[Lz__mm_] = '-';
                sb.Append(text);
                break;
            }
            PrintZone(sb);
            return sb.ToString();
        }

Usage Example

        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(Res.GetString("Sch_InvalidDateTimeOption", new object[] { dateTimeOption, "dateTimeOption" }));
            }
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.DateTime);
            return time.ToString();
        }
All Usage Examples Of System.Xml.Schema.XsdDateTime::ToString