page.title=RenderScript Time Functions and Types @jd:body

Overview

The functions below can be used to tell the current clock time and the current system up time. It is not recommended to call these functions inside of a kernel.

Summary

Types
rs_time_t Seconds since January 1, 1970
rs_tm Date and time structure
Functions
rsGetDt Elapsed time since last call
rsLocaltime Convert to local time
rsTime Seconds since January 1, 1970
rsUptimeMillis System uptime in milliseconds
rsUptimeNanos System uptime in nanoseconds

Types

rs_time_t : Seconds since January 1, 1970

A typedef of: int     When compiling for 32 bits.

A typedef of: long     When compiling for 64 bits.

Calendar time interpreted as seconds elapsed since the Epoch (00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)).

rs_tm : Date and time structure

A structure with the following fields:     

int tm_secSeconds after the minute. This ranges from 0 to 59, but possibly up to 60 for leap seconds.
int tm_minMinutes after the hour. This ranges from 0 to 59.
int tm_hourHours past midnight. This ranges from 0 to 23.
int tm_mdayDay of the month. This ranges from 1 to 31.
int tm_monMonths since January. This ranges from 0 to 11.
int tm_yearYears since 1900.
int tm_wdayDays since Sunday. This ranges from 0 to 6.
int tm_ydayDays since January 1. This ranges from 0 to 365.
int tm_isdstFlag to indicate whether daylight saving time is in effect. The value is positive if it is in effect, zero if it is not, and negative if the information is not available.

Data structure for broken-down time components.

Functions

rsGetDt : Elapsed time since last call

float rsGetDt();
Returns
Time in seconds.

Returns the time in seconds since this function was last called in this script.

rsLocaltime : Convert to local time

rs_tm* rsLocaltime(rs_tm* local, const rs_time_t* timer);
Parameters
localPointer to time structure where the local time will be stored.
timerInput time as a number of seconds since January 1, 1970.
Returns
Pointer to the output local time, i.e. the same value as the parameter local.

Converts the time specified by timer into a rs_tm structure that provides year, month, hour, etc. This value is stored at *local.

This functions returns the same pointer that is passed as first argument. If the local parameter is NULL, this function does nothing and returns NULL.

rsTime : Seconds since January 1, 1970

rs_time_t rsTime(rs_time_t* timer);
Parameters
timerLocation to also store the returned calendar time.
Returns
Seconds since the Epoch, -1 if there's an error.

Returns the number of seconds since the Epoch (00:00:00 UTC, January 1, 1970).

If timer is non-NULL, the result is also stored in the memory pointed to by this variable.

rsUptimeMillis : System uptime in milliseconds

int64_t rsUptimeMillis();
Returns
Uptime in milliseconds.

Returns the current system clock (uptime) in milliseconds.

rsUptimeNanos : System uptime in nanoseconds

int64_t rsUptimeNanos();
Returns
Uptime in nanoseconds.

Returns the current system clock (uptime) in nanoseconds.

The granularity of the values return by this call may be much larger than a nanosecond.