You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.0 KiB
104 lines
3.0 KiB
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;
|
|
}
|
|
/// <summary>
|
|
/// 获取当地服务器时区时间,
|
|
/// 以本地时区为准。
|
|
/// </summary>
|
|
/// <param name="time">来源时间</param>
|
|
/// <param name="localTimeZone">本地时区,最终时区</param>
|
|
/// <param name="targetTimeZone">来源时区</param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// 兼容AddServerTime的时间判断,时间填的是一天里的时间,比如10:12:16
|
|
/// </summary>
|
|
/// <param name="dailyTime"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|