virtweb_backend
virtweb_frontend/src
@ -1,3 +1,4 @@
|
||||
use chrono::Datelike;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
/// Get the current time since epoch
|
||||
@ -13,3 +14,15 @@ pub fn time() -> u64 {
|
||||
.unwrap()
|
||||
.as_secs()
|
||||
}
|
||||
|
||||
/// Format given UNIX time in a simple format
|
||||
pub fn format_date(time: i64) -> anyhow::Result<String> {
|
||||
let date = chrono::DateTime::from_timestamp(time, 0).ok_or(anyhow::anyhow!("invalid date"))?;
|
||||
|
||||
Ok(format!(
|
||||
"{:0>2}/{:0>2}/{}",
|
||||
date.day(),
|
||||
date.month(),
|
||||
date.year()
|
||||
))
|
||||
}
|
||||
|
Reference in New Issue
Block a user