Skip to main content

f64_to_datetime

Function f64_to_datetime 

Source
pub fn f64_to_datetime(timestamp_f64: f64) -> DateTime<Utc>
Expand description

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

This is a convenience function that converts a floating-point timestamp to a UTC datetime. For timezone-specific conversion, use f64_to_datetime_any.

§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

§Returns

Returns a DateTime representing the timestamp in UTC timezone.

§Panics

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

§Example

use strand_datetime_conversion::f64_to_datetime;

let timestamp = 1703518245.123456789;
let dt = f64_to_datetime(timestamp);
// dt will be 2023-12-25 15:30:45.123456789 UTC