Struct chrono::datetime::DateTime
[-] [+]
[src]
pub struct DateTime<Tz: TimeZone> { // some fields omitted }
ISO 8601 combined date and time with time zone.
Methods
impl<Tz: TimeZone> DateTime<Tz>
fn from_utc(datetime: NaiveDateTime, offset: Offset) -> DateTime<Tz>
Makes a new DateTime
with given UTC datetime and offset.
The local datetime should be constructed via the TimeZone
trait.
fn date(&self) -> Date<Tz>
Retrieves a date component.
fn time(&self) -> NaiveTime
Retrieves a time component.
Unlike date
, this is not associated to the time zone.
fn timestamp(&self) -> i64
Returns the number of non-leap seconds since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp").
fn num_seconds_from_unix_epoch(&self) -> i64
Same to DateTime::timestamp
.
fn offset<'a>(&'a self) -> &'a Offset
Retrieves an associated offset from UTC.
fn timezone(&self) -> Tz
Retrieves an associated time zone.
fn with_timezone<Tz2: TimeZone>(&self, tz: &Tz2) -> DateTime<Tz2>
Changes the associated time zone.
This does not change the actual DateTime
(but will change the string representation).
fn checked_add(self, rhs: Duration) -> Option<DateTime<Tz>>
Adds given Duration
to the current date and time.
Returns None
when it will result in overflow.
fn checked_sub(self, rhs: Duration) -> Option<DateTime<Tz>>
Subtracts given Duration
from the current date and time.
Returns None
when it will result in overflow.
fn naive_utc(&self) -> NaiveDateTime
Returns a view to the naive UTC datetime.
fn naive_local(&self) -> NaiveDateTime
Returns a view to the naive local datetime.
impl DateTime<FixedOffset>
fn parse_from_rfc2822(s: &str) -> ParseResult<DateTime<FixedOffset>>
Parses an RFC 2822 date and time string such as Tue, 1 Jul 2003 10:52:37 +0200
,
then returns a new DateTime
with a parsed FixedOffset
.
fn parse_from_rfc3339(s: &str) -> ParseResult<DateTime<FixedOffset>>
Parses an RFC 3339 and ISO 8601 date and time string such as 1996-12-19T16:39:57-08:00
,
then returns a new DateTime
with a parsed FixedOffset
.
Why isn't this named parse_from_iso8601
? That's because ISO 8601 allows some freedom
over the syntax and RFC 3339 exercises that freedom to rigidly define a fixed format.
fn parse_from_str(s: &str, fmt: &str) -> ParseResult<DateTime<FixedOffset>>
Parses a string with the specified format string and
returns a new DateTime
with a parsed FixedOffset
.
See the format::strftime
module on the supported escape sequences.
See also Offset::datetime_from_str
which gives a local DateTime
on specific time zone.
impl<Tz: TimeZone> DateTime<Tz> where Offset: Display
fn to_rfc2822(&self) -> String
Returns an RFC 2822 date and time string such as Tue, 1 Jul 2003 10:52:37 +0200
.
fn to_rfc3339(&self) -> String
Returns an RFC 3339 and ISO 8601 date and time string such as 1996-12-19T16:39:57-08:00
.
fn format_with_items<'a, I>(&self, items: I) -> DelayedFormat<I> where I: Iterator<Item=Item<'a>> + Clone
Formats the combined date and time with the specified formatting items.
fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the combined date and time with the specified format string.
See the format::strftime
module on the supported escape sequences.