pub struct Dayjs { /* private fields */ }Expand description
Dayjs struct representing a date and time with a time zone.
It contains:
tz: The time zone information as aTimeZoneenum.time: The UTC time as aDateTime<Utc>.
§Examples
use dayjs::{dayjs, Dayjs, TimeZone};
let now = dayjs();Implementations§
Source§impl Dayjs
impl Dayjs
Sourcepub fn from_object(obj: Value) -> Result<Self, String>
pub fn from_object(obj: Value) -> Result<Self, String>
Create Dayjs from JSON object
§Parameters
obj: JSON object containing “tz” and “time” fields
§Returns
Returns a Result with Dayjs on success, error message on failure
§Examples
use dayjs::Dayjs;
use serde_json::json;
let obj = json!({
"tz": "+08:00",
"time": "2025-12-21T14:30:00Z"
});
let d = Dayjs::from_object(obj).unwrap();Source§impl Dayjs
impl Dayjs
Sourcepub fn set_timezone(&mut self, tz: TimeZone)
pub fn set_timezone(&mut self, tz: TimeZone)
Set the time zone for the Dayjs instance.
Sourcepub fn get_timezone(&self) -> &TimeZone
pub fn get_timezone(&self) -> &TimeZone
Get the current time zone of the Dayjs instance.
Sourcepub fn get_timestamp(&self) -> i64
pub fn get_timestamp(&self) -> i64
Get the current time in UTC.
Sourcepub fn millisecond(&self) -> u32
pub fn millisecond(&self) -> u32
Get the millisecond (0-999)
Sourcepub fn day_of_year(&self) -> u32
pub fn day_of_year(&self) -> u32
Get the month number 1 ~ 366
Sourcepub fn week_of_year(&self) -> u32
pub fn week_of_year(&self) -> u32
Get the week number 1 ~ 53
Sourcepub fn month_of_year(&self) -> u32
pub fn month_of_year(&self) -> u32
Get the month number 1 ~ 12
Sourcepub fn set_minute(&mut self, minute: u32)
pub fn set_minute(&mut self, minute: u32)
Set the minute (0-59)
Sourcepub fn set_second(&mut self, second: u32)
pub fn set_second(&mut self, second: u32)
Set the second (0-59)
Sourcepub fn set_millisecond(&mut self, ms: u32)
pub fn set_millisecond(&mut self, ms: u32)
Set the millisecond (0-999)
Sourcepub fn clone_dayjs(&self) -> Dayjs
pub fn clone_dayjs(&self) -> Dayjs
Clone the Dayjs instance
Sourcepub fn days_in_month(&self) -> u32
pub fn days_in_month(&self) -> u32
Get the number of days in the month
Sourcepub fn is_leap_year(&self) -> bool
pub fn is_leap_year(&self) -> bool
Check if the year is a leap year
Trait Implementations§
Source§impl DiffTime for Dayjs
impl DiffTime for Dayjs
Source§fn diff(&self, other: &Dayjs, unit: Unit) -> i64
fn diff(&self, other: &Dayjs, unit: Unit) -> i64
Source§fn diff_milliseconds(&self, other: &Dayjs) -> i64
fn diff_milliseconds(&self, other: &Dayjs) -> i64
Source§fn diff_seconds(&self, other: &Dayjs) -> i64
fn diff_seconds(&self, other: &Dayjs) -> i64
Source§fn diff_minutes(&self, other: &Dayjs) -> i64
fn diff_minutes(&self, other: &Dayjs) -> i64
Source§fn diff_hours(&self, other: &Dayjs) -> i64
fn diff_hours(&self, other: &Dayjs) -> i64
Source§fn diff_weeks(&self, other: &Dayjs) -> i64
fn diff_weeks(&self, other: &Dayjs) -> i64
Source§fn diff_months(&self, other: &Dayjs) -> i64
fn diff_months(&self, other: &Dayjs) -> i64
Source§fn diff_years(&self, other: &Dayjs) -> i64
fn diff_years(&self, other: &Dayjs) -> i64
Source§impl Display for Dayjs
Display implementation for Dayjs
Displays the UTC time in ISO 8601 format (e.g., 2025-12-21T14:29:42.009427Z)
impl Display for Dayjs
Display implementation for Dayjs Displays the UTC time in ISO 8601 format (e.g., 2025-12-21T14:29:42.009427Z)
Source§impl DisplayTime for Dayjs
impl DisplayTime for Dayjs
Source§fn to_timestamp(&self) -> i64
fn to_timestamp(&self) -> i64
Converts the time to a timestamp in seconds.
Source§impl OperationTime for Dayjs
impl OperationTime for Dayjs
Source§fn add_months(&mut self, months: i32)
fn add_months(&mut self, months: i32)
Add a duration to the current time in month.
Source§fn add_minutes(&mut self, minutes: i32)
fn add_minutes(&mut self, minutes: i32)
Add a duration to the current time in minutes.
Source§fn add_seconds(&mut self, seconds: i32)
fn add_seconds(&mut self, seconds: i32)
Add a duration to the current time in seconds.
Source§fn add_milliseconds(&mut self, milliseconds: i32)
fn add_milliseconds(&mut self, milliseconds: i32)
Add a duration to the current time in milliseconds.
Source§fn subtract_years(&mut self, years: i32)
fn subtract_years(&mut self, years: i32)
Subtract a duration from the current time in year.
Source§fn subtract_months(&mut self, months: i32)
fn subtract_months(&mut self, months: i32)
Subtract a duration from the current time in month.
Source§fn subtract_weeks(&mut self, weeks: i32)
fn subtract_weeks(&mut self, weeks: i32)
Subtract a duration from the current time in week.
Source§fn subtract_days(&mut self, days: i32)
fn subtract_days(&mut self, days: i32)
Subtract a duration from the current time in day.
Source§fn subtract_hours(&mut self, hours: i32)
fn subtract_hours(&mut self, hours: i32)
Subtract a duration from the current time in hours.
Source§fn subtract_minutes(&mut self, minutes: i32)
fn subtract_minutes(&mut self, minutes: i32)
Subtract a duration from the current time in minutes.
Source§fn subtract_seconds(&mut self, seconds: i32)
fn subtract_seconds(&mut self, seconds: i32)
Subtract a duration from the current time in seconds.
Source§fn subtract_milliseconds(&mut self, milliseconds: i32)
fn subtract_milliseconds(&mut self, milliseconds: i32)
Subtract a duration from the current time in milliseconds.