add time format string util
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
dc18f89c0b
commit
2dd68d3fa5
2 changed files with 11 additions and 3 deletions
|
@ -208,7 +208,7 @@ features = ["serde"]
|
|||
# standard date and time tools
|
||||
[workspace.dependencies.chrono]
|
||||
version = "0.4.38"
|
||||
features = ["alloc"]
|
||||
features = ["alloc", "std"]
|
||||
default-features = false
|
||||
|
||||
[workspace.dependencies.hyper]
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[allow(clippy::as_conversions)]
|
||||
pub fn now_millis() -> u64 {
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
UNIX_EPOCH
|
||||
.elapsed()
|
||||
.expect("positive duration after epoch")
|
||||
|
@ -18,3 +18,11 @@ pub fn rfc2822_from_seconds(epoch: i64) -> String {
|
|||
.unwrap_or_default()
|
||||
.to_rfc2822()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn format(ts: SystemTime, str: &str) -> String {
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
let dt: DateTime<Utc> = ts.into();
|
||||
dt.format(str).to_string()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue