using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Sog { public static class ConfigStringTimeParse { public static long ParseConfigTime(string time) { if (string.IsNullOrEmpty(time)) { return 0; } DateTime result; bool bSuccess = DateTime.TryParse(time, out result); if (bSuccess == false) { return 0; } long timeSecond = AppTime.GetTimeSecond(result); return timeSecond; } /// /// 获取当地服务器时区时间, /// 以本地时区为准。 /// /// 来源时间 /// 本地时区,最终时区 /// 来源时区 /// public static long ParseConfigTimeWithTimeZone(string time, int localTimeZone, int targetTimeZone) { if (string.IsNullOrEmpty(time)) { return 0; } DateTime result; bool bSuccess = DateTime.TryParse(time, out result); if (bSuccess == false) { return 0; } long timeSecond = AppTime.GetTimeSecond(result); //0也是时区! //if (targetTimeZone != 0) { long diffTimeZone = (localTimeZone - targetTimeZone) * 3600; timeSecond += diffTimeZone; } return timeSecond; } /// /// 兼容AddServerTime的时间判断,时间填的是一天里的时间,比如10:12:16 /// /// /// public static long ParseDailyConfigTime(long nowSecond, string dailyTime) { if (string.IsNullOrEmpty(dailyTime)) { return 0; } DateTime now = AppTime.ConvertUnixTimeToDateTime(nowSecond * 1000); string stringNow = now.ToString("u").Substring(0, 11); string descStartTime = stringNow + dailyTime; DateTime result; bool bSuccess = DateTime.TryParse(descStartTime, out result); if (bSuccess == false) { return 0; } long timeSecond = AppTime.GetTimeSecond(result); return timeSecond; } public static bool ParseConfigTime(string time, out DateTime dateTime) { dateTime = DateTime.Now; if (string.IsNullOrEmpty(time)) { return false; } //DateTime result; bool bSuccess = DateTime.TryParse(time, out dateTime); if (bSuccess == false) { return false; } return true; } } }