Last active
November 26, 2015 07:27
-
-
Save osya/55c1e6e594dfac9c92ca to your computer and use it in GitHub Desktop.
Convert ArcGIS DateTime #datetime #CSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Strategis.Server.SpatialProcessor.DataInterop.ArcGis | |
{ | |
public static class ArcGisDateTimeHelper | |
{ | |
/**********************************************************************************/ | |
// Declarations | |
/**********************************************************************************/ | |
private static readonly DateTime DateTimeBase = new DateTime(1970, 1, 1, 0, 0, 0, 0); | |
/**********************************************************************************/ | |
// Functions | |
/**********************************************************************************/ | |
public static Int64? DateTimeToUnixTime(DateTime? dateTime) | |
{ | |
if (dateTime == null || dateTime.Value < DateTimeBase) | |
{ | |
return null; | |
} | |
TimeSpan span = dateTime.Value.ToLocalTime() - DateTimeBase; | |
return Math.Max((Int64)span.TotalMilliseconds, 0); | |
} | |
/**********************************************************************************/ | |
public static DateTime UnixTimeToDateTime(Int64 unixTime) | |
{ | |
if (unixTime == 0) | |
{ | |
return DateTime.MinValue; | |
} | |
return DateTimeBase.AddMilliseconds(unixTime).ToLocalTime(); | |
} | |
/**********************************************************************************/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment