Hi,
using chrono
, how do we automatically retrieve the current browser's locale to print a nice localized string to the user ?
The date is constructed from a timestamp (i64).
In pure javascript, I do:
const formattedDate = new Intl.DateTimeFormat(navigator.language).format(date);
The issue with the above is that I miss the hours and minutes.
But with the chrono
package, I have to give the offset myself. And I don't know how to dynamically retrieve it.
My current try:
if timestamp_nano == 0 {
return None;
}
timestamp_nano /= 1000;
match Utc.timestamp_opt(timestamp_nano, 0) {
chrono::offset::LocalResult::Single(dt) | chrono::offset::LocalResult::Ambiguous(dt, _) => {
info!("TIME {:?}", dt);
Some(dt.to_rfc2822());
}
chrono::offset::LocalResult::None => {
info!("TIME error");
None
}
}
from the timestamp
Any help ?
Thanks