예제 #1
0
        internal static void WriteDateTimeString(TextWriter writer, DateTime value, TimeSpan offset, DateTimeKind kind, DateFormatHandling format)
        {
            if (format == DateFormatHandling.MicrosoftDateFormat)
            {
                long num = JsonConvert.ConvertDateTimeToJavaScriptTicks(value, offset);
                writer.Write("\"\\/Date(");
                writer.Write(num);
                switch (kind)
                {
                case DateTimeKind.Unspecified:
                    if (value != DateTime.MaxValue && value != DateTime.MinValue)
                    {
                        JsonConvert.WriteDateTimeOffset(writer, offset, format);
                        break;
                    }
                    else
                    {
                        break;
                    }

                case DateTimeKind.Local:
                    JsonConvert.WriteDateTimeOffset(writer, offset, format);
                    break;
                }
                writer.Write(")\\/\"");
            }
            else
            {
                writer.Write("\"");
                writer.Write(value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFF", (IFormatProvider)CultureInfo.InvariantCulture));
                switch (kind)
                {
                case DateTimeKind.Utc:
                    writer.Write("Z");
                    break;

                case DateTimeKind.Local:
                    JsonConvert.WriteDateTimeOffset(writer, offset, format);
                    break;
                }
                writer.Write("\"");
            }
        }