예제 #1
0
        byte[] GetOffset()
        {
            int tickCount = Environment.TickCount;

            if (_offsetCacheTime + 1000 < tickCount)
            {
                _offsetCacheTime = tickCount;
                var offset  = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);
                var builder = new JsonUtf8Builder();
                if (offset.TotalMinutes > 0)
                {
                    builder.AppendAscii('+');
                }
                else
                {
                    builder.AppendAscii('-');
                }
                builder.AppendIntTwo(Math.Abs(offset.Hours));
                builder.AppendAscii(':');
                builder.AppendIntTwo(offset.Minutes);
                var offsetSpan = builder.AsSpan();
                for (int index = 0; index < 6; index++)
                {
                    _offset[index] = offsetSpan[index];
                }
            }
            return(_offset);
        }
예제 #2
0
        string GetOffset()
        {
            int tickCount = Environment.TickCount;

            if (_offsetCacheTime + 1000 < tickCount)
            {
                _offsetCacheTime = tickCount;
                var offset  = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);
                var builder = new JsonUtf8Builder();
                if (offset.TotalMinutes > 0)
                {
                    builder.Append('+');
                }
                else
                {
                    builder.Append('-');
                }
                builder.AppendIntTwo(Math.Abs(offset.Hours));
                builder.Append(':');
                builder.AppendIntTwo(offset.Minutes);
                _offset = builder.ToString();
            }
            return(_offset);
        }