Cross-platform C SDK logo

Cross-platform C SDK

Time

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Access to the internal computer clock.


Functions

uint64_tbtime_now (void)
voidbtime_date (...)
uint64_tbtime_to_micro (...)
voidbtime_to_date (...)

The operating system measures the passage of time using an internal clock, typically implemented by a counter of the ticks that have passed since an initial moment called epoch. In Unix-like systems this counter represents the number of seconds elapsed since January 1, 1970 UTC. However, in Windows it represents the number of 100 nanosecond intervals since January 1, 1601 coinciding with the beginning of the Gregorian calendar. In NAppGUI these values ​​have been unified to work with Unix Epoch on all platforms.

  • Use btime_now to get the number of micro-seconds elapsed since January 1, 1970 UTC.
  • Use btime_date to get the system date.
  • Use btime_to_micro and btime_to_date to convert dates to Unix Time and vice versa.
  • Image showing the second 0 of the Unix Epoch.
    Figure 1: Unix Epoch Instant 0.

The difference between two instants will give us the time elapsed during the execution of a task.

1
2
3
4
5
6
7
uint64_t ed, st = btime_now();

// Do something...
...

ed = btime_now();
bstd_printf("Total elapsed micro-seconds: %lu\n", ed - st);
❮ Back
Next ❯

btime_now ()

Gets the number of micro-seconds elapsed since January 1, 1970 until this precise moment. Use the difference between instants to know the time consumed by a process.

uint64_t
btime_now(void);

Return

The number of micro-seconds elapsed, that is, the number of intervals of 1/1000000 seconds.

Remarks

The initial instant is January 1, 1970 in Unix/Linux systems and January 1, 1601 in Windows since it is the first year of the Gregorian cycle in which Windows NT was activated. This function equates both starts, always returning the Unix time.


btime_date ()

Gets the current system date.

void
btime_date(Date *date);
date

Current date.


btime_to_micro ()

Convert a date to Unix Time.

uint64_t
btime_to_micro(const Date *date);
date

The date to convert.

Return

The number of micro-seconds since January 1, 1970 UTC.


btime_to_date ()

Transform Unix Time into a date.

void
btime_to_date(const uint64_t micro,
              Date *date);
micro

Number of micro-seconds since January 1, 1970 UTC.

date

Result date.

❮ Back
Next ❯