pub struct DateUtil;
Implementations§
Source§impl DateUtil
impl DateUtil
Sourcepub fn parse_with_format(
date_str: &str,
format: &str,
) -> Option<DateTime<Local>>
pub fn parse_with_format( date_str: &str, format: &str, ) -> Option<DateTime<Local>>
使用指定格式解析日期字符串
Sourcepub fn format_date(date: DateTime<Local>) -> String
pub fn format_date(date: DateTime<Local>) -> String
格式化为标准日期 yyyy-MM-dd
Sourcepub fn format_datetime(date: DateTime<Local>) -> String
pub fn format_datetime(date: DateTime<Local>) -> String
格式化为标准日期时间 yyyy-MM-dd HH:mm:ss
Sourcepub fn format_time(date: DateTime<Local>) -> String
pub fn format_time(date: DateTime<Local>) -> String
格式化为标准时间 HH:mm:ss
Sourcepub fn day_of_week(date: DateTime<Local>) -> u32
pub fn day_of_week(date: DateTime<Local>) -> u32
获取星期几 (1-7, 周一到周日)
Sourcepub fn last_month() -> DateTime<Local>
pub fn last_month() -> DateTime<Local>
上个月
Sourcepub fn next_month() -> DateTime<Local>
pub fn next_month() -> DateTime<Local>
下个月
Sourcepub fn between(
start: DateTime<Local>,
end: DateTime<Local>,
unit: DateUnit,
) -> i64
pub fn between( start: DateTime<Local>, end: DateTime<Local>, unit: DateUnit, ) -> i64
计算两个日期之间的差值
Sourcepub fn format_between(between_ms: i64, level: Level) -> String
pub fn format_between(between_ms: i64, level: Level) -> String
格式化时间差
Sourcepub fn get_zodiac(month: u32, day: u32) -> &'static str
pub fn get_zodiac(month: u32, day: u32) -> &'static str
获取星座
Sourcepub fn get_chinese_zodiac(year: i32) -> &'static str
pub fn get_chinese_zodiac(year: i32) -> &'static str
获取生肖
Sourcepub fn age_of_now(birth_date_str: &str) -> Option<u32>
pub fn age_of_now(birth_date_str: &str) -> Option<u32>
计算年龄
Sourcepub fn is_leap_year(year: i32) -> bool
pub fn is_leap_year(year: i32) -> bool
判断是否闰年
Sourcepub fn range(
start: DateTime<Local>,
end: DateTime<Local>,
unit: DateUnit,
) -> DateRange ⓘ
pub fn range( start: DateTime<Local>, end: DateTime<Local>, unit: DateUnit, ) -> DateRange ⓘ
创建日期范围迭代器
Sourcepub fn range_contains(
range1: DateRange,
range2: DateRange,
) -> Vec<DateTime<Local>>
pub fn range_contains( range1: DateRange, range2: DateRange, ) -> Vec<DateTime<Local>>
计算两个范围的交集
Auto Trait Implementations§
impl Freeze for DateUtil
impl RefUnwindSafe for DateUtil
impl Send for DateUtil
impl Sync for DateUtil
impl Unpin for DateUtil
impl UnwindSafe for DateUtil
Blanket Implementations§
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Approximate the subject to a given type with the default scheme.
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Approximate the subject to a given type with a specific scheme.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.