Struct Utc

pub 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);

Trait Implementations

impl Clone for Utc

fn clone(&self) -> Self

impl Copy for Utc

impl Debug for Utc

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

impl Display for Utc

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

impl Eq for Utc

impl Hash for Utc

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

impl Offset for Utc

fn fix(&self) -> FixedOffset

impl PartialEq for Utc

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

impl StructuralPartialEq for Utc

impl TimeZone for Utc

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

Auto Trait Implementations

impl Freeze for Utc

impl RefUnwindSafe for Utc

impl Send for Utc

impl Sync for Utc

impl Unpin for Utc

impl UnsafeUnpin for Utc

impl UnwindSafe for Utc

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> CloneToUninit for Utc where T: Clone,

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

impl<T> From<T> for Utc

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Utc where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for Utc where T: Display + ?Sized,

fn to_string(&self) -> String

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

fn into(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<U> for Utc where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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