Home >Backend Development >Golang >How to Convert a 12-Byte Int96 Timestamp to a GoLang Timestamp?

How to Convert a 12-Byte Int96 Timestamp to a GoLang Timestamp?

Susan Sarandon
Susan SarandonOriginal
2024-12-22 12:33:18833browse

How to Convert a 12-Byte Int96 Timestamp to a GoLang Timestamp?

Converting Parquet Int96 Timestamp to GoLang

In this scenario, you have a 12-byte int96 timestamp array and want to convert it to a timestamp in GoLang.

Typically, int96 timestamps consist of an 8-byte nanoseconds part and a 4-byte date part stored as a Julian day number. However, in this case, the first 8 bytes are actually nanoseconds, not milliseconds, and the epoch is midnight, not the Unix epoch.

To illustrate the conversion process, let's consider the following int96 timestamp:

To interpret it correctly:

  1. Reverse the first 8 bytes to obtain the nanoseconds part: 0x0000000029324BFD
  2. Convert it to an integer: 45296 * 10^9 nanoseconds
  3. Convert the result to seconds: 45296 seconds
  4. Extract the time components from the seconds: 12 hours 34 minutes 56 seconds
  5. Reverse the last 4 bytes to obtain the Julian day number: 0x00256859
  6. Convert it to an integer: 2451545
  7. Look up the corresponding date using a Julian day calendar: 2000-01-01

Therefore, the int96 timestamp [128 76 69 116 64 7 0 0 48 131 37 0] represents the timestamp 2000-01-01 12:34:56 in GoLang.

The above is the detailed content of How to Convert a 12-Byte Int96 Timestamp to a GoLang Timestamp?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn