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

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

This sample measures a sleep with the uptime, sets the wall clock and reads it back a second later, and waits for a condition with `PBL_POLL_SLEEP_MS()`, once for one that comes true and once for one that never does.

The uptime never jumps, so it is what durations and timeouts are measured with; the wall clock is for telling the time.

Run:

`pbl samples samples/kernel/time`

Boards:

every board

## Sources

src/main.c

```
#include \<errno.h\>#include \<inttypes.h\>#include \<pbl/kernel/delay.h\>#include \<pbl/kernel/time.h\>#include \<pbl/logging/logging.h\>/\* 2026-01-01 00:00:00 UTC \*/#define NEW\_YEAR 1767225600static bool prv\_device\_ready(void) {static unsigned int s\_polls;return ++s\_polls \>= 3;}int main(void) {uint64\_t start\_ms;int ret;/\* Uptime only moves forward: use it to measure and to time out. \*/start\_ms = pbl\_uptime\_ms();pbl\_sleep\_ms(50);PBL\_LOG\_INFO("time: slept 50 ms, uptime moved by at least 50 ms: %s",pbl\_uptime\_ms() - start\_ms \>= 50 ? "yes" : "no");/\* The wall clock follows the uptime, and jumps when it is set. \*/pbl\_realtime\_set(NEW\_YEAR);pbl\_sleep\_ms(1000);PBL\_LOG\_INFO("time: one second after it was set, the wall clock moved by %" PRId32 " s",(int32\_t)(pbl\_realtime() - NEW\_YEAR));/\* Waiting for a condition, with the time limit every such wait needs. \*/ret = PBL\_POLL\_SLEEP\_MS(prv\_device\_ready(), 5, 100);PBL\_LOG\_INFO("time: device ready: %s", ret == 0 ? "yes" : "no");ret = PBL\_POLL\_SLEEP\_MS(false, 5, 20);PBL\_LOG\_INFO("time: a condition that never holds returns %s",ret == -ETIMEDOUT ? "-ETIMEDOUT" : "something else");PBL\_LOG\_INFO("Sample done");return 0;}
```

## 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 -ETIMEDOUT
Sample done
```

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