Questions tagged [rust-chrono]

Date and time handling for Rust. (also known as rust-chrono) It aims to be a feature-complete superset of the time library.

Chrono is a date and time handling for Rust. In particular,

  • Chrono strictly adheres to ISO 8601.
  • Chrono is timezone-aware by default, with separate timezone-naive types.
  • Chrono is space-optimal and (while not being the primary goal) reasonably efficient.

Links:

83 questions
61
votes
2 answers

How do I add days to a Chrono UTC?

I am trying to find the preferred way to add days to a Chrono UTC. I want to add 137 days to the current time: let dt = UTC::now();
schmoopy
  • 6,419
  • 11
  • 54
  • 89
29
votes
1 answer

Rust Chrono parse date String, ParseError(NotEnough) and ParseError(TooShort)

How to convert a String to a chrono::DateTime or chrono::NaiveDateTime And what does the ParseError(NotEnough) or ParseError(TooShort) mean?
Ralph Bisschops
  • 1,888
  • 1
  • 22
  • 34
24
votes
3 answers

How do I go from a NaiveDate to a specific TimeZone with Chrono?

I am parsing dates and times in Rust using the chrono crate. The dates and times are from a website in which the date and time are from different sections of the page. The date is shown in the format %d/%m/%Y (example: 27/08/2018). The time is shown…
Justmaker
  • 1,261
  • 2
  • 11
  • 20
21
votes
3 answers

How to convert Unix time / time since the epoch to standard date and time?

I'm using the chrono crate; after some digging I discovered the DateTime type has a function timestamp() which could generate epoch time of type i64. However, I couldn't find out how to convert it back to DateTime. extern crate chrono; use…
Sajuuk
  • 2,667
  • 3
  • 22
  • 34
18
votes
4 answers

How to convert DateTime to DateTime or vice versa?

I have a struct that contains a timestamp. For that I am using the chrono library. There are two ways to get the timestamp: Parsed from a string via DateTime::parse_from_str which results in a DateTime The current time, received by…
buster
  • 1,071
  • 1
  • 10
  • 15
15
votes
1 answer

Rust Diesel: the trait bound `NaiveDateTime: Deserialize<'_>` is not satisfied

I am new to rust and diesel. And trying to create a small demo api using rocket framework. Getting error: the trait bound NaiveDateTime: Deserialize<'_> is not satisfied I googled and found some useful links like here :…
Shaksham Singh
  • 491
  • 1
  • 5
  • 19
15
votes
2 answers

How to use a custom serde deserializer for chrono timestamps?

I'm trying to parse JSON into a struct which has a chrono::DateTime field. The JSON has the timestamps saved in a custom format that I wrote a deserializer for. How do I connect the two and get it working using #[serde(deserialize_with)]? I'm using…
Emre
  • 503
  • 4
  • 7
12
votes
3 answers

What does ParseError(NotEnough) from rust-chrono mean?

I'm using rust-chrono and I'm trying to parse a date like this: extern crate chrono; use chrono::*; fn main() { let date_str = "2013-02-14 15:41:07"; let date = DateTime::parse_from_str(&date_str, "%Y-%m-%d %H:%M:%S"); match date { …
Caballero
  • 11,546
  • 22
  • 103
  • 163
10
votes
4 answers

How do I add a month to a Chrono NaiveDate?

I am trying to create a date picker and I need to navigate between months let current = NaiveDate::parse_from_str("2020-10-15", "%Y-%m-%d").unwrap(); How can I generate the date 2020-11-15?
Towhid Zeinali
  • 197
  • 2
  • 9
10
votes
1 answer

Converting from NaiveDateTime to DateTime

Rust's chrono has been very frustrating to work with as it makes converting from timezones very difficult. For example: my user inputs a string. I parse this into a naive date time using NaiveDateTime::parse_from_str. Now I would like to convert…
Thor Correia
  • 1,159
  • 1
  • 12
  • 20
10
votes
2 answers

Getting the current time in specified timezone

Using the Chrono-TZ library, how can I get the current time in a specified time zone? I tried let naive_dt = Local::now().naive_local(); let dt = Los_Angeles.from_local_datetime(&naive_dt).unwrap(); println!("{:#?}", dt); But this printed the…
Synesso
  • 37,610
  • 35
  • 136
  • 207
8
votes
3 answers

How do I parse ISO 8601 duration strings using Chrono?

While chrono supports parsing of date, time and time zone in ISO 8601 compliant format, I am unable to find any method in the crate to parse duration strings such as PT2M which represents 2 minutes.
praveent
  • 562
  • 3
  • 10
8
votes
3 answers

How do I handle Unix timestamps using chrono?

I can't seem to work out how to handle Unix timestamps in Rust with chrono. I have the following code, however the naive and therefore the datetime vars are incorrect: use chrono::{Utc, DateTime, NaiveDateTime}; fn main() { println!("Hello,…
utx0_
  • 1,364
  • 14
  • 24
8
votes
2 answers

Get date of start/end of week

I'm need the chrono::Date of the first and last date of a week from the current year. I have two issues, first I'm unable to get chrono to parse the week of current year and second I'm unable to get the first/last date of the week. (There are a lot…
Florian sp1rit
  • 575
  • 1
  • 7
  • 20
8
votes
1 answer

Unable to deserialize chrono::DateTime from json

I encounter an interesting issue. For some reason serde is unable to deserialize a chrono::DateTime object from a string in the same format it was serialized (but it does if I save a variable with it): use chrono; // 0.4.11 use serde_json; //…
Netwave
  • 40,134
  • 6
  • 50
  • 93
1
2 3 4 5 6