-
Notifications
You must be signed in to change notification settings - Fork 3
/
TimeZoneHelper.cs
32 lines (27 loc) · 1.02 KB
/
TimeZoneHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PcrBattleChannel
{
internal static class TimeZoneHelper
{
private const string TimeZoneName = "China Standard Time";
private static TimeZoneInfo _beijing = TimeZoneInfo.CreateCustomTimeZone(TimeZoneName,
TimeSpan.FromHours(8), TimeZoneName, TimeZoneName);
public static DateTime ToBeijingTime(DateTime utc)
{
return TimeZoneInfo.ConvertTimeFromUtc(utc, _beijing);
}
public static DateTime GetGameDate(DateTime beijingTime)
{
if (beijingTime.Date == DateTime.MinValue)
{
return beijingTime.Date;
}
return beijingTime.Date - (beijingTime.TimeOfDay < TimeSpan.FromHours(5) ? TimeSpan.FromDays(1) : default);
}
public static DateTime BeijingNow => ToBeijingTime(DateTime.UtcNow);
public static DateTime GameTimeToday => GetGameDate(BeijingNow);
}
}