Skip to content

Instantly share code, notes, and snippets.

@osya
Last active November 26, 2015 07:27
Show Gist options
  • Save osya/55c1e6e594dfac9c92ca to your computer and use it in GitHub Desktop.
Save osya/55c1e6e594dfac9c92ca to your computer and use it in GitHub Desktop.
Convert ArcGIS DateTime #datetime #CSharp
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