pub trait ZonedClock: Clock {
// Required method
fn timezone(&self) -> Tz;
// Provided method
fn local_time(&self) -> DateTime<Tz> { ... }
}Expand description
A trait representing a clock with timezone support.
This trait extends Clock to provide timezone information and methods
to get the current local time in the clock’s timezone.
§Examples
use prism3_clock::{Clock, ZonedClock, SystemClock, Zoned};
use chrono_tz::Asia::Shanghai;
let clock = Zoned::new(SystemClock::new(), Shanghai);
let local = clock.local_time();
println!("Local time in Shanghai: {}", local);§Author
Haixing Hu
Required Methods§
Provided Methods§
Sourcefn local_time(&self) -> DateTime<Tz>
fn local_time(&self) -> DateTime<Tz>
Returns the current local time in this clock’s timezone.
This method has a default implementation that converts the UTC time
from time() to the local time using the clock’s
timezone.
§Returns
The current local time as a DateTime<Tz> object.
§Examples
use prism3_clock::{ZonedClock, SystemClock, Zoned};
use chrono_tz::Asia::Shanghai;
let clock = Zoned::new(SystemClock::new(), Shanghai);
let local = clock.local_time();
println!("Local time: {}", local);