System Grab Bag

Timestamp Parser and Converter


Or try... now, today, yesterday, tomorrow (timestamp list)
  • Date and Time: 2024-11-20 12:46:26 (subtract day | add day)
  • Unix Timestamp: 1732106786
  • Unix Timestamp (Milliseconds): 1732106786226
  • LDAP Timestamp and Windows File Time (FILETIME): 133765803862260000
  • .NET Timestamp (System.DateTime): 638677035862260000
  • OLE Timestamp: 45616.53224798611
  • Mac HFS+ Timestamp: 3814951586
  • Cocoa Core Timestamp: 753799586

Converting Between Different Timestamp Types

There are different types of timestamps used in modern computer systems. One of, or potentially the most, popular is the Unix timestamp, which counts either the seconds or milliseconds since an epoch, known as the Unix epoch. The Unix epoch is on January 1, 1970 at 00:00:00 UTC (12:00:00 AM UTC).

Converting Between Epochs

If you have a Unix timestamp and want to convert it to a different epoch, you can do so by subtracting the Unix timestamp of the new epoch from your timestamp you want to convert. For example... if you want to convert the timestamp for the timestamp you requested above (1732106786) with the epoch of Jauary 1, 2000 instead of January 1, 1970, you can perform the steps below.
  1. Convert January 1, 2000 into a Unix timestamp (946684800)
  2. Get the Unix timestamp of the value you want to convert (in this case 1732106786)
  3. Perform a simple subtraction (1732106786 - 946684800 = 785421986)
  4. You now have a timestamp with that epoch.
To convert it back to a timestamp that uses the Unix epoch, you can do the process in reverse.
  1. Convert January 1, 2000 into a Unix timestamp (946684800)
  2. Take your timestamp and add it (785421986 + 946684800 = 1732106786)
  3. You now have a timestamp with the Unix epoch.

Convert Unix and Mac HFS+ Timestamps

Mac HFS+ timestamps are simply "Unix timestamps" with a different epoch (i.e. the only difference between them is that the epoch is January 1, 1904 (an epoch of -2082844800 in Unix time)). You can follow the steps below to convert a Unix timestamp and Mac HFS+ timestamp to and fro.
  1. Convert January 1, 1904 into a Unix timestamp (-2082844800)
  2. Get the Unix timestamp of the value you want to convert (in this case 1732106786)
  3. Perform a simple subtraction (1732106786 - -2082844800 = 3814951586)
  4. You now have a timestamp with that epoch.
To convert it back to a timestamp that uses the Unix epoch, you can do the process in reverse.
  1. Convert January 1, 1904 into a Unix timestamp (-2082844800)
  2. Take your timestamp and add it (3814951586 + -2082844800 = 1732106786)
  3. You now have a timestamp with the Unix epoch.

Convert Unix and Cocoa Core Timestamps

Like Mac HFS+ timestamps, the only difference is a different epoch (January 1, 2001).You can follow the steps below to convert a Unix timestamp and Cocoa Core timestamp.
  1. Convert January 1, 2001 into a Unix timestamp (978307200)
  2. Get the Unix timestamp of the value you want to convert (in this case 1732106786)
  3. Perform a simple subtraction (1732106786 - 978307200 = 753799586)
  4. You now have a timestamp with that epoch.
To convert it back to a timestamp that uses the Unix epoch, you can do the process in reverse.
  1. Convert January 1, 2001 into a Unix timestamp (978307200)
  2. Take your timestamp and add it (753799586 + 978307200 = 1732106786)
  3. You now have a timestamp with the Unix epoch.
See the Apple developer documentation for CFAbsoluteTime for more information.

Convert a .NET Timestamp to a Unix Timestamp

.NET has the System.DateTimeOffset class which can be used to quickly convert between Unix timestamps to .NET timestamps and back again. The C# code example below converts between Unix timestamps to a .NET timestamp.
	using System;

	const Int64 UnixTimestamp = 1732106786L;
	DateTimeOffset datetime = DateTimeOffset.FromUnixTimeSeconds(UnixTimestamp);
	Console.WriteLine(datetime.Ticks);
	
And it is just as simple to convert a .NET Timestamp to a Unix timestamp.
	using System;

	const Int64 DotNetTimestamp = 638677035862260000L;
	DateTimeOffset datetime = new DateTimeOffset(DotNetTimestamp);
	Console.WriteLine(datetime.ToUnixTimeSeconds());
	
If you have or want Unix time in milliseconds, you can use FromUnixTimeMilliseconds and ToUnixTimeMilliseconds instead.