Struct TimeUtils

Source
pub struct TimeUtils;
Expand description

时间工具

Implementations§

Source§

impl TimeUtils

Source

pub fn current_timestamp() -> i64

获取当前时间戳(秒)

Source

pub fn current_timestamp_millis() -> i64

获取当前时间戳(毫秒)

Source

pub fn current_datetime_str() -> String

获取当前日期时间字符串

Source

pub fn current_date_str() -> String

获取当前日期字符串

Source

pub fn current_time_str() -> String

获取当前时间字符串

Source

pub fn timestamp_to_datetime_str(timestamp: i64) -> String

时间戳转日期时间字符串

Source

pub fn datetime_str_to_timestamp(datetime_str: &str) -> Option<i64>

日期时间字符串转时间戳

Source

pub fn format_datetime(datetime: DateTime<Local>, format: &str) -> String

格式化日期时间

Source

pub fn parse_datetime( datetime_str: &str, format: &str, ) -> Option<DateTime<Local>>

解析日期时间字符串

Source

pub fn diff_seconds(start: DateTime<Local>, end: DateTime<Local>) -> i64

计算两个时间的差值(秒)

Source

pub fn add_seconds(datetime: DateTime<Local>, seconds: i64) -> DateTime<Local>

增加秒数

Source

pub fn add_minutes(datetime: DateTime<Local>, minutes: i64) -> DateTime<Local>

增加分钟

Source

pub fn add_hours(datetime: DateTime<Local>, hours: i64) -> DateTime<Local>

增加小时

Source

pub fn add_days(datetime: DateTime<Local>, days: i64) -> DateTime<Local>

增加天数

Source

pub fn is_same_day(dt1: DateTime<Local>, dt2: DateTime<Local>) -> bool

是否为同一天

Source

pub fn is_today(dt: DateTime<Local>) -> bool

是否为今天

Source

pub fn start_of_day(dt: DateTime<Local>) -> DateTime<Local>

获取开始时间

Source

pub fn end_of_day(dt: DateTime<Local>) -> DateTime<Local>

获取结束时间

Source

pub fn current_datetime() -> DateTime<Utc>

获取当前时间

Source

pub fn to_local(dt: &DateTime<Utc>) -> DateTime<Local>

转换为本地时间

Source

pub fn serialize_optional_datetime<S>( value: &Option<DateTime<Utc>>, serializer: S, ) -> Result<S::Ok, S::Error>
where S: Serializer,

序列化响应的时间格式

Source

pub fn deserialize_optional_datetime<'de, D>( deserializer: D, ) -> Result<Option<DateTime<Utc>>, D::Error>
where D: Deserializer<'de>,

Source

pub fn format_duration(duration: Duration) -> String

格式化时间间隔

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V