System.DateTimeOffset 中新增的Unix 時間戳方法

// System.DateTimeOffset
[__DynamicallyInvokable]
public static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds)
{
    if (milliseconds < -62135596800000L || milliseconds > 253402300799999L)
    {
        throw new ArgumentOutOfRangeException("milliseconds", string.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), -62135596800000L, 253402300799999L));
    }
    long ticks = milliseconds * 10000L + 621355968000000000L;
    return new DateTimeOffset(ticks, TimeSpan.Zero);
}
// System.DateTimeOffset
[__DynamicallyInvokable]
public static DateTimeOffset FromUnixTimeSeconds(long seconds)
{
	if (seconds < -62135596800L || seconds > 253402300799L)
	{
		throw new ArgumentOutOfRangeException("seconds", string.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), -62135596800L, 253402300799L));
	}
	long ticks = seconds * 10000000L + 621355968000000000L;
	return new DateTimeOffset(ticks, TimeSpan.Zero);
}

  

// System.DateTimeOffset
[__DynamicallyInvokable]
public long ToUnixTimeMilliseconds()
{
    long num = this.UtcDateTime.Ticks / 10000L;
    return num - 62135596800000L;
}
// System.DateTimeOffset
[__DynamicallyInvokable]
public long ToUnixTimeSeconds()
{
	long num = this.UtcDateTime.Ticks / 10000000L;
	return num - 62135596800L;
}

  爲了這四個方法特地裝了VS2015,你沒看錯,是2015this

相關文章
相關標籤/搜索