pub struct FmtLocal2k { /* private fields */ }local only.Expand description
§Formatted Local UTC2K.
This is the formatted companion to Local2k. You can use it to obtain a
string version of the date, print it, etc.
While this acts essentially as a glorified String, it is sized exactly
and therefore requires less memory to represent. It also implements Copy.
It follows the simple Unix date format of YYYY-MM-DD hh:mm:ss.
Speaking of, you can obtain an &str using AsRef<str>,
Borrow<str>, or FmtLocal2k::as_str.
If you only want the date or time half, call FmtLocal2k::date or
FmtLocal2k::time respectively.
See Local2k for limitations and gotchas.
Implementations§
Source§impl FmtLocal2k
§Instantiation.
impl FmtLocal2k
§Instantiation.
Source§impl FmtLocal2k
§Getters.
impl FmtLocal2k
§Getters.
Sourcepub const fn as_bytes(&self) -> &[u8] ⓘ
pub const fn as_bytes(&self) -> &[u8] ⓘ
§As Bytes.
Return a byte string slice in YYYY-MM-DD hh:mm:ss format.
A byte slice can also be obtained using FmtLocal2k::as_ref.
§Examples
use utc2k::{Local2k, Utc2k};
let fmt = Local2k::from(Utc2k::MAX).formatted();
assert_eq!(
fmt.as_bytes(),
b"2099-12-31 15:59:59", // e.g. California.
);Sourcepub const fn date(&self) -> &str
pub const fn date(&self) -> &str
§Just the Date Bits.
This returns the date as a string slice in YYYY-MM-DD format.
§Examples
use utc2k::{Local2k, Utc2k};
let utc = Utc2k::new(2025, 6, 19, 18, 57, 12);
let fmt = Local2k::from(utc).formatted();
assert_eq!(
fmt.as_str(),
"2025-06-19 11:57:12", // e.g. California.
);
assert_eq!(fmt.date(), "2025-06-19");Sourcepub const fn time(&self) -> &str
pub const fn time(&self) -> &str
§Just the Time Bits.
This returns the time as a string slice in hh:mm:ss format.
§Examples
use utc2k::{Local2k, Utc2k};
let utc = Utc2k::new(2025, 6, 19, 18, 57, 12);
let fmt = Local2k::from(utc).formatted();
assert_eq!(
fmt.as_str(),
"2025-06-19 11:57:12", // e.g. California.
);
assert_eq!(fmt.time(), "11:57:12");Source§impl FmtLocal2k
§Conversion.
impl FmtLocal2k
§Conversion.
Sourcepub fn to_rfc2822(&self) -> String
pub fn to_rfc2822(&self) -> String
§To RFC2822.
Return a string formatted according to RFC2822.
§Examples
use utc2k::{Local2k, Utc2k};
// A proper UTC date in RFC2822.
let utc = Utc2k::new(2021, 12, 13, 04, 56, 1);
assert_eq!(
utc.to_rfc2822(),
"Mon, 13 Dec 2021 04:56:01 +0000",
);
// The same date localized to, say, California.
let local = Local2k::from(utc).formatted();
assert_eq!(
local.to_rfc2822(),
"Sun, 12 Dec 2021 20:56:01 -0800",
);The RFC2822 date/time format is portable, whether local or UTC.
let utc_2822 = utc.to_rfc2822();
let local_2822 = local.to_rfc2822();
// The RFC2822 representations will vary if there's an offset, but
// if parsed back into a Utc2k, that'll get sorted and they'll match!
assert_eq!(
Utc2k::from_rfc2822(utc_2822.as_bytes()),
Some(utc),
);
assert_eq!(
Utc2k::from_rfc2822(local_2822.as_bytes()),
Some(utc),
);Sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
§To RFC3339.
Return a string formatted according to RFC3339.
§Examples
use utc2k::{Local2k, Utc2k};
// A proper UTC date in RFC3339.
let utc = Utc2k::new(2021, 12, 13, 11, 56, 1);
assert_eq!(utc.to_rfc3339(), "2021-12-13T11:56:01Z");
// The same date localized to, say, California.
let local = Local2k::from(utc).formatted();
assert_eq!(local.to_rfc3339(), "2021-12-13T03:56:01-0800");The RFC3339 date/time format is portable, whether local or UTC.
let utc_3339 = utc.to_rfc3339();
let local_3339 = local.to_rfc3339();
// The RFC3339 representations will vary if there's an offset, but
// if parsed back into a Utc2k, that'll get sorted and they'll match!
assert_eq!(
Utc2k::from_ascii(utc_3339.as_bytes()),
Some(utc),
);
assert_eq!(
Utc2k::from_ascii(local_3339.as_bytes()),
Some(utc),
);Trait Implementations§
Source§impl AsRef<[u8]> for FmtLocal2k
impl AsRef<[u8]> for FmtLocal2k
Source§impl AsRef<str> for FmtLocal2k
impl AsRef<str> for FmtLocal2k
Source§impl Borrow<str> for FmtLocal2k
impl Borrow<str> for FmtLocal2k
Source§impl Clone for FmtLocal2k
impl Clone for FmtLocal2k
Source§fn clone(&self) -> FmtLocal2k
fn clone(&self) -> FmtLocal2k
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more