---
title: "Time in Rust"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/rust/kernel/time/
last_updated: 2026-11-18
sdk_version: 4.44
---
# Time in Rust

Source: https://developer.repebble.com/pebbleos/docs/samples/rust/kernel/time/

The [time sample](https://developer.repebble.com/pebbleos/docs/samples/kernel/time.md) written in [Rust](https://developer.repebble.com/pebbleos/docs/development/build_system/rust.md), on the `pebbleos` crate.

Durations are `core::time::Duration`, uptime is an `Instant`, and `time::poll()` waits for a condition with a time limit.

Run:

`pbl samples samples/rust/kernel/time`

Boards:

every board

## Sources

src/lib.rs

```
#![no\_std]use core::time::Duration;use pebbleos::println;use pebbleos::thread;use pebbleos::time::{self, Instant};// 2026-01-01 00:00:00 UTCconst NEW\_YEAR: i64 = 1767225600;#[pebbleos::main]fn main() {// Uptime only moves forward: use it to measure and to time out.let start = Instant::now();thread::sleep(Duration::from\_millis(50));println!("time: slept 50 ms, uptime moved by at least 50 ms: {}",yes\_no(start.elapsed() \>= Duration::from\_millis(50)));// The wall clock follows the uptime, and jumps when it is set.time::set\_realtime(NEW\_YEAR);thread::sleep(Duration::from\_secs(1));println!("time: one second after it was set, the wall clock moved by {} s",time::realtime() - NEW\_YEAR);// Waiting for a condition, with the time limit every such wait needs.let mut polls = 0;let ret = time::poll(Duration::from\_millis(5), Duration::from\_millis(100), || {polls += 1;polls \>= 3});println!("time: device ready: {}", yes\_no(ret.is\_ok()));let ret = time::poll(Duration::from\_millis(5), Duration::from\_millis(20), || {false});println!("time: a condition that never holds returns {ret:?}");println!("Sample done");}fn yes\_no(b: bool) -\> &'static str {if b { "yes" } else { "no" }}
```

## Output

```
time: slept 50 ms, uptime moved by at least 50 ms: yes
time: one second after it was set, the wall clock moved by \d s
time: device ready: yes
time: a condition that never holds returns Err\(ETIMEDOUT\)
Sample done
```

Generated from PebbleOS [7753e801d](https://github.com/coredevices/pebbleos/commit/7753e801d93d20f2d37534ce2fa69d9952015237). This page is maintained in the pebbleos repository: [docs/samples/rust/kernel/time.md](https://github.com/coredevices/pebbleos/blob/7753e801d93d20f2d37534ce2fa69d9952015237/docs/samples/rust/kernel/time.md).
