30 lines
811 B
C#
30 lines
811 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WebAPIServer.Extensions
|
|
{
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|