DateTime

Struct DateTime 

Source
pub struct DateTime {
    pub year: usize,
    pub month: usize,
    pub day: usize,
    pub hour: usize,
    pub minute: usize,
    pub second: usize,
    pub millisecond: usize,
    pub day_of_year: usize,
    pub weekday: usize,
    pub timestamp: i64,
    pub offset: i16,
}

Fields§

§year: usize

[0, +oo)

§month: usize

[1, 12]

§day: usize

[1, 31]

§hour: usize

[0, 23]

§minute: usize

[0, 59]

§second: usize

[0, 59]

§millisecond: usize

[0, 999]

§day_of_year: usize

[1, 365]

§weekday: usize

[1, 7]

§timestamp: i64

时间戳, 单位:毫秒.

§offset: i16

时间偏移, 比如用+0800表示东八区的时间偏移, 即+08:00.

Implementations§

Source§

impl DateTime

Source

pub fn new() -> Self

返回当前时间, 等同于:

DateTime::from((DateTime::now(), None));
Source

pub fn now() -> i64

返回当前系统的时间戳, 单位:毫秒.

Source

pub fn to_utc(&self) -> Self

转成国际标准时间.

Trait Implementations§

Source§

impl Clone for DateTime

Source§

fn clone(&self) -> DateTime

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<(i64, Option<i16>)> for DateTime

Source§

fn from(value: (i64, Option<i16>)) -> Self

从时间戳转成DateTime.

  • @param value (timestamp, offset)
  • @param value$0 时间戳, 单位:毫秒.
  • @param value$1 时间偏移, 默认是系统设置的时区所对应的偏移.
Source§

impl From<(usize, usize, usize, usize, usize, usize, usize, Option<i16>)> for DateTime

Source§

fn from( value: (usize, usize, usize, usize, usize, usize, usize, Option<i16>), ) -> Self

从设置好的时间, 转成DateTime.

  • @param value (year, month, day, hour, minute, second, millisecond, offset)
  • @param value$0 年.
  • @param value$1 月.
  • @param value$2 日.
  • @param value$3 时.
  • @param value$4 分.
  • @param value$5 秒.
  • @param value$6 毫秒.
  • @param value$7 时间偏移, 默认是系统设置的时区所对应的偏移.
§Panics

如果参数不符合特定的数值范围就会panic.

例如, ’时’的范围是0~23, 如果对应的入参是24, 就会panic.

例如, 某一年的二月份, 只有28天, 但是参数’日’的入参是29, 就会panic.

Source§

impl PartialEq for DateTime

Source§

fn eq(&self, other: &DateTime) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToString for DateTime

Source§

fn to_string(&self) -> String

转成字符串, 使用RFC3339标准, 格式’xx-xx-xxTxx:xx:xx.xxx[+/-]xx:xx’.

Source§

impl StructuralPartialEq for DateTime

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.