pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

Time

Standard system time functions.

This module contains standard time functions and formatters for printing. Note that Pebble now supports both local time and UTC time (including timezones and daylight savings time). Most of these functions are part of the C standard library which is documented at https://sourceware.org/newlib/libc.html#Timefns

Function Documentation

int strftime(char * s, size_t maxsize, const char * format, const struct tm * tm_p)

Format the time value at tm according to fmt and place the result in a buffer s of size max.

Parameters

s

A preallocation char array of size max

maxsize

the size of the array s

format

a formatting string

tm_p

A pointer to a struct tm containing a broken out time value

Returns

The number of bytes placed in the array s, not including the null byte, 0 if the value does not fit.

struct tm * localtime(const time_t * timep)

convert the time value pointed at by clock to a struct tm which contains the time adjusted for the local timezone

Parameters

timep

A pointer to an object of type time_t that contains a time value

Returns

A pointer to a struct tm containing the broken out time value adjusted for the local timezone

struct tm * gmtime(const time_t * timep)

convert the time value pointed at by clock to a struct tm which contains the time expressed in Coordinated Universal Time (UTC)

Parameters

timep

A pointer to an object of type time_t that contains a time value

Returns

A pointer to a struct tm containing Coordinated Universal Time (UTC)

time_t mktime(struct tm * tb)

convert the broken-down time structure to a timestamp expressed in Coordinated Universal Time (UTC)

Parameters

tb

A pointer to an object of type tm that contains broken-down time

Returns

The number of seconds since epoch, January 1st 1970

time_t time(time_t * tloc)

Obtain the number of seconds since epoch. Note that the epoch is not adjusted for Timezones and Daylight Savings.

Parameters

tloc

Optionally points to an address of a time_t variable to store the time in. If you only want to use the return value, you may pass NULL into tloc instead

Returns

The number of seconds since epoch, January 1st 1970

double difftime(time_t end, time_t beginning)

Obtain the number of seconds elapsed between beginning and end represented as a double.

Note

Pebble uses software floating point emulation. Including this function which returns a double will significantly increase the size of your binary. We recommend directly subtracting both timestamps to calculate a time difference.

int difference = ts1 - ts2;

Parameters

end

A time_t variable representing some number of seconds since epoch, January 1st 1970

beginning

A time_t variable representing some number of seconds since epoch, January 1st 1970. Note that end should be greater than beginning, but this is not enforced.

Returns

The number of seconds elapsed between beginning and end.

uint16_t time_ms(time_t * t_utc, uint16_t * out_ms)

Obtain the number of seconds and milliseconds part since the epoch. This is a non-standard C function provided for convenience.

Parameters

tloc

Optionally points to an address of a time_t variable to store the time in. You may pass NULL into tloc if you don't need a time_t variable to be set with the seconds since the epoch

out_ms

Optionally points to an address of a uint16_t variable to store the number of milliseconds since the last second in. If you only want to use the return value, you may pass NULL into out_ms instead

Returns

The number of milliseconds since the last second

time_t time_start_of_today(void)

Return the UTC time that corresponds to the start of today (midnight).

Returns

the UTC time corresponding to the start of today (midnight)

Typedef Documentation

typedef unsigned int time_t

time in seconds since the epoch, January 1st 1970

Macro Definition Documentation

#define TZ_LEN 6
#define SECONDS_PER_MINUTE (60)
#define MINUTES_PER_HOUR (60)
#define SECONDS_PER_HOUR (SECONDS_PER_MINUTE * MINUTES_PER_HOUR)
#define HOURS_PER_DAY (24)
#define MINUTES_PER_DAY (HOURS_PER_DAY * MINUTES_PER_HOUR)
#define SECONDS_PER_DAY (MINUTES_PER_DAY * SECONDS_PER_MINUTE)

Need some help?

Functions

  • strftime
  • localtime
  • gmtime
  • mktime
  • time
  • difftime
  • time_ms
  • time_start_of_today

Typedefs

  • time_t

Macro Defintions

  • TZ_LEN
  • SECONDS_PER_MINUTE
  • MINUTES_PER_HOUR
  • SECONDS_PER_HOUR
  • HOURS_PER_DAY
  • MINUTES_PER_DAY
  • SECONDS_PER_DAY

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!