#unix-timestamp #timestamp #date-time #unix #epoch-time #epoch

bin+lib uts2ts

Convert a unix timestamp (seconds) to a struct {year, month, day, hour, minute, second, weekday}

7 unstable releases (3 breaking)

0.4.1 Aug 5, 2023
0.4.0 Aug 2, 2023
0.3.0 Jul 29, 2023
0.2.2 Jul 27, 2023
0.1.0 Jul 25, 2023

#349 in Date and time

Download history 134/week @ 2024-07-22 266/week @ 2024-07-29 146/week @ 2024-08-05 181/week @ 2024-08-12 114/week @ 2024-08-19 146/week @ 2024-08-26 51/week @ 2024-09-02 62/week @ 2024-09-09 60/week @ 2024-09-16 104/week @ 2024-09-23 54/week @ 2024-09-30 55/week @ 2024-10-07 46/week @ 2024-10-14 125/week @ 2024-10-21 39/week @ 2024-10-28 75/week @ 2024-11-04

299 downloads per month
Used in rustypaste

MIT license

15KB
225 lines

uts2ts

Continuous Integration Continuous Deployment GitHub Tag Crate Release Documentation

uts2ts is a simple function that does only one thing:

It converts a unix timestamp to something slightly more useful. ;-)

So why then? Well, it's not always warranted to pull in a myriad of dependencies when you need this one, little thingy.

For complex time and date calculations and manipulations, please refer to the more functional complete crates chrono and time.

Please note that the as_string() method is just a quick way of generating a human readable date/time string that

  • is unambiguous and close to ISO 8601 (or RFC 3339)
  • can be used as an example how to write your own formatting function
  • is NOT an attempt to reinvent all the goodies other crates provide

Examples

use uts2ts::uts2ts;

fn main() {
    let ts = uts2ts(204158100);

    // Timestamp { year: 1976, month: 6, day: 20, hour: 22, minute: 35, second: 0, weekday: 0 }
    println!("{:?}", ts);

    // 1976-06-20 22:35:00
    println!("{}", ts.as_string());

    // 1976-06-20 22:35:00 +0000
    println!("{}", ts.as_string_utc());
}

No runtime deps