初始化项目
This commit is contained in:
29
Services/Extensions/TimeExtensions.cs
Normal file
29
Services/Extensions/TimeExtensions.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System
|
||||
{
|
||||
public static class TimeExtensions
|
||||
{
|
||||
public static DateTime? ToDateTime(this string timeStamp)
|
||||
{
|
||||
long ticks = 0L;
|
||||
if (long.TryParse(timeStamp, out ticks))
|
||||
{
|
||||
DateTime dateTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||||
TimeSpan value = new TimeSpan(ticks);
|
||||
return new DateTime?(dateTime.Add(value));
|
||||
}
|
||||
DateTime now = DateTime.Now;
|
||||
if (DateTime.TryParse(timeStamp, out now))
|
||||
{
|
||||
return new DateTime?(now);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user