Esempio n. 1
0
        public override void WriteDate(DateTime datetime)
        {
            writer.Write((byte)Datatypes.DATE_DATATYPE_V1);
            DateTime olddate = new DateTime(1970, 1, 1);

#if (FULL_BUILD || PURE_CLIENT_LIB)
            // get the offset of the time zone the server is in
            double localTimezoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(olddate).TotalMilliseconds;

            // convert 1/1/1970 12AM to UTC
            olddate = TimeZone.CurrentTimeZone.ToUniversalTime(olddate);
#else
            // get the offset of the time zone the server is in
            double localTimezoneOffset = TimeZoneInfo.Local.GetUtcOffset(olddate).TotalMilliseconds;

            // convert 1/1/1970 12AM to UTC
            olddate = TimeZoneInfo.ConvertTime(olddate, TimeZoneInfo.Utc);
#endif
            // bring it back to 12AM
            olddate = olddate.AddMilliseconds(localTimezoneOffset);

            datetime = datetime.ToUniversalTime();
            TimeSpan span    = datetime.Subtract(olddate);
            long     totalMs = ((long)span.TotalMilliseconds);
            writer.WriteDouble(totalMs);

            writer.WriteShort((short)0);
        }
Esempio n. 2
0
        public override void WriteDate(DateTime datetime)
        {
            writer.Write((byte)Datatypes.DATE_DATATYPE_V3);
            writer.WriteVarInt(0x1);
#if ( WINDOWS_PHONE8 )
            TimeSpan timeZoneOffset = TimeZoneInfo.Local.BaseUtcOffset;
#else
            TimeSpan timeZoneOffset = TimeZoneInfo.Local.GetUtcOffset(datetime);
#endif
            DateTime olddate = new DateTime(1970, 1, 1);//.ToUniversalTime();
            TimeSpan span    = datetime.Subtract(olddate);
            span = span.Subtract(timeZoneOffset);
            long totalMs = ((long)span.TotalMilliseconds);
            writer.WriteDouble(totalMs);
        }