Skip to main content

f64_to_datetime_any

Function f64_to_datetime_any 

Source
pub fn f64_to_datetime_any<TZ>(timestamp_f64: f64, tz: TZ) -> DateTime<TZ>
where TZ: TimeZone,
Expand description

Converts an f64 timestamp to a chrono::DateTime in the specified timezone.

This function provides full control over the target timezone for the converted datetime. The input timestamp is interpreted as seconds since Unix epoch (always in UTC), but the resulting DateTime will be in the specified timezone.

§Arguments

  • timestamp_f64 - A floating-point timestamp where the integer part represents seconds since Unix epoch and the fractional part represents nanoseconds as a decimal fraction
  • tz - The target timezone for the resulting DateTime

§Returns

Returns a DateTime representing the timestamp in the specified timezone.

§Panics

Panics if the timestamp is invalid or out of range for the chrono library.

§Example

use chrono::Utc;
use strand_datetime_conversion::f64_to_datetime_any;

let timestamp = 1703518245.123456789;
let dt_utc = f64_to_datetime_any(timestamp, Utc);
// dt_utc will be 2023-12-25 15:30:45.123456789 UTC