-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating a DateTime from epoch milliseconds #264
Comments
So, we need to convert millis to nanosec first? |
Possible way use chrono::{DateTime, TimeZone, NaiveDateTime, Utc};
fn main() {
let time = chrono::Utc::now();
let ts_millis = time.timestamp_millis();
println!("timestamp milli {} -> {}", time, ts_millis);
let ts_secs = ts_millis / 1000;
let ts_ns = (ts_millis % 1000) * 1_000_000 ;
let dt = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(ts_secs, ts_ns as u32), Utc);
println!("timestamp milli {} -> {}", dt, dt.timestamp_millis());
} |
Could we add a |
I'm open to reviewing a PR for that. |
Wouldn't it be better if it were |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been able to convert a
DateTime
to milliseconds withtimestamp_millis()
, but I am struggling to find a trait member that allows me to get a DateTime with milliseconds.Is it currently possible to do this?
The text was updated successfully, but these errors were encountered: