Example #1
0
        public static string Print(this long timeInMillis, TimeZoneInfo timeZoneInfo = null)
        {
            if (timeZoneInfo == null)
            {
                timeZoneInfo = TimeZoneInfo.Local;
            }

            return(Print(DateTimeOffsetHelper.TimeFromMillis(timeInMillis, timeZoneInfo)));
        }
Example #2
0
        public static DateTimeOffset AsDateTimeOffset(this object value, TimeZoneInfo timeZone)
        {
            if (value is DateTimeOffset dateTimeOffsetValue)
            {
                return(dateTimeOffsetValue.TranslateTo(timeZone));
            }
            if (value is DateTime dateTimeValue)
            {
                return(dateTimeValue.TranslateTo(timeZone));
            }
            if (value is long longValue)
            {
                return(DateTimeOffsetHelper.TimeFromMillis(longValue, timeZone));
            }
            if (value is int intValue)
            {
                return(DateTimeOffsetHelper.TimeFromMillis(intValue, timeZone));
            }

            throw new ArgumentException("invalid value for datetime", nameof(value));
        }
Example #3
0
        public static DateTimeOffset AsDateTimeOffset(this object value, TimeZoneInfo timeZone)
        {
            if (value is DateTimeOffset)
            {
                return(((DateTimeOffset)value).TranslateTo(timeZone));
            }
            if (value is DateTime)
            {
                return(((DateTime)value).TranslateTo(timeZone));
            }
            if (value is long)
            {
                return(DateTimeOffsetHelper.TimeFromMillis((long)value, timeZone));
            }
            if (value is int)
            {
                return(DateTimeOffsetHelper.TimeFromMillis((int)value, timeZone));
            }

            throw new ArgumentException("invalid value for datetime", "value");
        }
Example #4
0
 public DateTimeEx SetUtcMillis(long millis)
 {
     _dateTime = DateTimeOffsetHelper.TimeFromMillis(millis, _timeZone);
     return(this);
 }
Example #5
0
        public static DateTimeEx GetInstance(TimeZoneInfo timeZoneInfo, long timeInMillis)
        {
            var baseDt = DateTimeOffsetHelper.TimeFromMillis(timeInMillis, timeZoneInfo);

            return(new DateTimeEx(baseDt, timeZoneInfo));
        }