{
  "id": 6130380,
  "title": "A faster way to convert a timestamp to Hour, Min, Sec",
  "url": "https://urgent.news/2026/09/07/a-faster-way-to-convert-a-timestamp-to-hour-min-sec",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-07T10:27:56.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://www.benjoffe.com/fast-time-of-day"
  },
  "original_language": "en",
  "account": "Many major date/time libraries compute hour, minute and second in a sequential manner, which can be slow. This article explores a faster approach to convert a daily timestamp [0..86399] into Hour, Minute and Second using only two multiplications (and fewer CPU cycles). The speed boost comes from two main ideas: bitwise hacks and manual implementation of division by multiplication and shifting.\n\nMost libraries compute time components sequentially, creating a dependency chain where each step depends on the previous ones. This makes it difficult to parallelize the computation. However, by rearranging the problem and computing intermediate results (like minute) from multiple sources, the dependency chain can be shortened.\n\nOne approach is to manually implement a multiplication-shift for division, which can speed up the computation on certain processors. This method is accurate for up to 626 hours and can provide a speed boost on 32-bit and x86 processors, as well as some SIMD chips.\n\nAnother approach is to compute intermediate results in reverse order, calculating the second early and working backward through the chain. This method, used in the .NET runtime, performs better than traditional methods due to direct computation of tmin and its availability for concurrent steps. However, some compilers may not recognize this optimization.\n\nIn summary, by re-structuring the problem and applying manual optimizations, it is possible to achieve a faster conversion of timestamps to Hour, Minute and Second, with shorter dependency chains and better performance on various processors.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}