pub struct Datetime<'a> { /* private fields */ }Expand description
A precise point in time along associated to a Timezone.
The Datetime cannot be created on its own as it depends on
a Timezone. tzdata does not expose a naive flavor of Datetime.
To build a Datetime, instanciate a Timezone first and call
the desired method.
let paris = tzdata::Timezone::new("Europe/Paris").unwrap();
let midnight_in_paris = paris.datetime(2015, 12, 25, 0, 0, 0, 0);
let utc = tzdata::Timezone::utc();
let t = midnight_in_paris.project(&utc);
assert_eq!(t.date(), (2015, 12, 24));
assert_eq!(t.time(), (23, 0, 0, 0));Implementations§
Source§impl<'a> Datetime<'a>
impl<'a> Datetime<'a>
Sourcepub fn project<'b>(&self, tz: &'b Timezone) -> Datetime<'b>
pub fn project<'b>(&self, tz: &'b Timezone) -> Datetime<'b>
Project the current Datetime in another Timezone.
Sourcepub fn date(&self) -> (i32, i32, i32)
pub fn date(&self) -> (i32, i32, i32)
Return the date component of the Datetime expressed
in the associated Timezone. The tuple holds the
year, month and day in this order.
Sourcepub fn time(&self) -> (i32, i32, i32, i32)
pub fn time(&self) -> (i32, i32, i32, i32)
Return the time component of the Datetime expressed
in the associated Timezone. The tuple holds
the hour, minute, second and nanosecond in this order.
Sourcepub fn unix(&self) -> i64
pub fn unix(&self) -> i64
Return the unix timestamp. This is the number of unix seconds since 1970-01-01T00:00:00Z.
Sourcepub fn format(&self, fmt: &str) -> String
pub fn format(&self, fmt: &str) -> String
Format the Datetime according to the provided format.
The following control characters are implemented:
%%: the ‘%’ character%Y: year (2006)%m: month (01)%d: day of the month (02)%e: day of the month (2)%H: hour (15)%M: minute (04)%S: second (05)%3: millisecond (123)%6: microsecond (123456)%9: nanosecond (123456789)%x: UTC offset (+02:00 or -05:00)%z: UTC offset (+0200 or -0500)%Z: timezone abbreviation (CET)%w: weekday (1)%a: abbreviated weekday name (Mon)%A: full weekday name (Monday)%b: abbreviated month name (Jan)%B: full month name (January)%C: century (20)
Panics if the format is invalid.