昨天時間戳

查找昨天 00:00:00 UTC 的 Unix 時間戳,並複製附近的參考時間戳用於每日日期範圍。

Yesterday at 00:00 UTC

Yesterday midnight is commonly used as the lower bound for daily reports, scheduled jobs, and log searches. Pair it with today midnight to query exactly one UTC day.

Avoid timezone drift

This reference uses UTC so that scripts behave the same on laptops, servers, CI jobs, and cloud functions. Convert to a local timezone only when the user-facing display requires it.

Building a yesterday date range

A reliable yesterday filter needs two boundaries: yesterday at 00:00:00 UTC and today at 00:00:00 UTC. Query everything greater than or equal to the first boundary and strictly less than the second. This avoids missing records with milliseconds and avoids including the first record from the next day.

  • Use yesterdayMidnight as the inclusive lower bound
  • Use todayMidnight as the exclusive upper bound
  • Keep both boundaries in the same unit: seconds with seconds, milliseconds with milliseconds
  • Convert to a local timezone only if yesterday means a local calendar day

Verifying yesterday's boundary

Convert the copied value back to a UTC string and confirm it is exactly 00:00:00 for the previous UTC date. For one-day exports, also copy today's midnight value and use it as the exclusive upper bound. That pair gives a complete day even when records include milliseconds. If your product reports yesterday in a local timezone, generate both local boundaries first, then convert them to epoch values.