Home > OS >  How to get end-of-today in milliseconds?
How to get end-of-today in milliseconds?

Time:07-11

In Java, we can get end of today like this:

public static Long getEndOfToday() {
        Long endOfDay = LocalDateTime.now()
                .with(LocalTime.MAX)
                .toInstant(ZoneOffset.of(" 8"))
                .toEpochMilli();
        return endOfDay;
}

How would I go about getting the end of the day as a Unix timestamp in Rust?

CodePudding user response:

You can use the chrono crate and achieve what you want like so:

use chrono::Local; // 0.4.19

fn end_of_today() -> i64 {
    Local::today()
        .and_hms_milli(23, 59, 59, 999)
        .timestamp_millis()
}
  • Related