Struct Utc

struct Utc

The UTC time zone. This is the most efficient time zone when you don't need the local time. It is also used as an offset (which is also a dummy type).

Using the TimeZone methods on the UTC struct is the preferred way to construct DateTime<Utc> instances.

Example

use chrono::{DateTime, TimeZone, Utc};

let dt = DateTime::from_timestamp(61, 0).unwrap();

assert_eq!(Utc.timestamp_opt(61, 0).unwrap(), dt);
assert_eq!(Utc.with_ymd_and_hms(1970, 1, 1, 0, 1, 1).unwrap(), dt);

Implementations

impl Utc

fn today() -> Date<Utc>

Returns a Date which corresponds to the current date.

fn now() -> DateTime<Utc>

Returns a DateTime<Utc> which corresponds to the current date and time in UTC.

See also the similar Local::now() which returns DateTime<Local>, i.e. the local date and time including offset from UTC.

Example

# #![allow(unused_variables)]
# use chrono::{FixedOffset, Utc};
// Current time in UTC
let now_utc = Utc::now();

// Current date in UTC
let today_utc = now_utc.date_naive();

// Current time in some timezone (let's use +05:00)
let offset = FixedOffset::east_opt(5 * 60 * 60).unwrap();
let now_with_offset = Utc::now().with_timezone(&offset);

impl Clone for Utc

fn clone(self: &Self) -> Utc

impl Copy for Utc

impl Debug for Utc

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

impl Display for Utc

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

impl Eq for Utc

impl Freeze for Utc

impl Hash for Utc

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl Offset for Utc

fn fix(self: &Self) -> FixedOffset

impl PartialEq for Utc

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

impl RefUnwindSafe for Utc

impl Send for Utc

impl StructuralPartialEq for Utc

impl Sync for Utc

impl TimeZone for Utc

fn from_offset(_state: &Utc) -> Utc
fn offset_from_local_date(self: &Self, _local: &NaiveDate) -> MappedLocalTime<Utc>
fn offset_from_local_datetime(self: &Self, _local: &NaiveDateTime) -> MappedLocalTime<Utc>
fn offset_from_utc_date(self: &Self, _utc: &NaiveDate) -> Utc
fn offset_from_utc_datetime(self: &Self, _utc: &NaiveDateTime) -> Utc

impl Unpin for Utc

impl UnsafeUnpin for Utc

impl UnwindSafe for Utc

impl<T> Any for Utc

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Utc

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Utc

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

impl<T> CloneToUninit for Utc

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

impl<T> From for Utc

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Utc

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for Utc

fn to_string(self: &Self) -> String

impl<T, U> Into for Utc

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for Utc

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

impl<T, U> TryInto for Utc

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