System Grab Bag

Timestamp Parser and Converter


Or try... now, today, yesterday, tomorrow (timestamp list)
  • Date and Time: 2024-06-30 01:55:05 (subtract day | add day)
  • Unix Timestamp: 1719712505
  • Unix Timestamp (Milliseconds): 1719712505172
  • LDAP Timestamp and Windows File Time (FILETIME): 133641861051720000
  • .NET Timestamp (System.DateTime): 638553093051720000
  • OLE Timestamp: 45473.079920972224
  • Mac HFS+ Timestamp: 3802557305
  • Cocoa Core Timestamp: 741405305

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 (1719712505) 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 1719712505)
  3. Perform a simple subtraction (1719712505 - 946684800 = 773027705)
  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 (773027705 + 946684800 = 1719712505)
  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 1719712505)
  3. Perform a simple subtraction (1719712505 - -2082844800 = 3802557305)
  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 (3802557305 + -2082844800 = 1719712505)
  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 1719712505)
  3. Perform a simple subtraction (1719712505 - 978307200 = 741405305)
  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 (741405305 + 978307200 = 1719712505)
  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 = 1719712505L;
	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 = 638553093051720000L;
	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.