RenderScript 时间函数和类型
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
概览
以下函数可用于告知当前时钟时间和当前系统时间。建议不要在内核中调用这些函数。
总结
类型
rs_time_t
:自 1970 年 1 月 1 日以来的秒数
以下类型定义符:int 针对 32 位进行编译时。
以下类型定义符:long 针对 64 位进行编译时。
日历时间,被解释为自纪元(1970 年 1 月 1 日 1970 年 1 月 1 日 00:00:00,世界协调时间 [UTC])起经过的秒数。
rs_tm
:日期和时间结构
一个包含以下字段的结构:
int tm_sec | 分钟之后的秒数。介于 0 到 59 之间,但对于闰秒,范围最高可达 60。 |
整数 tm_min | 分钟,在小时后。范围是 0 到 59。 |
整数 tm_hour | 午夜过后的小时数。范围是 0 到 23。 |
整数 tm_mday | 日期。范围是 1 到 31。 |
int tm_mon | 自 1 月以来的月数。范围从 0 到 11。 |
整数 tm_year | 自 1900 年以来的年份。 |
整数 tm_wday | 自星期日以来的天数。范围是 0 到 6。 |
整数 tm_yday | 自 1 月 1 日以来的天数。范围是 0 到 365。 |
int tm_isdst | 此标记指示夏令时是否生效。如果有效,则该值为正,否则为 0,如果没有信息,则值为负。 |
细分时间组件的数据结构。
函数
rsGetDt
:自上次调用以来经过的时间
返回自在此脚本中上次调用此函数后经过的时间(以秒为单位)。
rsLocaltime
:转换为当地时间
参数
本地 | 一个指针,指向将在其中存储本地时间的时间结构。 |
定时器 | 输入自 1970 年 1 月 1 日以来的秒数。 |
开球回攻次数
指向输出当地时间的指针,即与参数 local 相同的值。 |
将计时器指定的时间转换为提供年、月、小时等条件的 rs_tm 结构。此值存储在 *local。
此函数返回作为第一个参数传递的同一指针。如果本地参数为 NULL,则此函数不执行任何操作并返回 NULL。
rsTime
:自 1970 年 1 月 1 日以来的秒数
返回自纪元(世界协调时间,UTC,1970 年 1 月 1 日 00:00:00)以来的秒数。
如果计时器为非 NULL 值,结果还会存储在此变量所指向的内存中。
rsUptimeMillis
:系统正常运行时间(以毫秒为单位)
rsUptimeNanos
:系统正常运行时间(以纳秒为单位)
以纳秒为单位返回当前系统时钟(正常运行时间)。
此调用返回的值的粒度可能远大于一纳秒。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# RenderScript Time Functions and Types\n\nOverview\n--------\n\nThe functions below can be used to tell the current clock time and the current\nsystem up time. It is not recommended to call these functions inside of a kernel.\n\nSummary\n-------\n\n| Types ||\n|--------------------------------------------------------------------------------|-------------------------------|\n| [rs_time_t](/guide/topics/renderscript/reference/rs_time#android_rs:rs_time_t) | Seconds since January 1, 1970 |\n| [rs_tm](/guide/topics/renderscript/reference/rs_time#android_rs:rs_tm) | Date and time structure |\n\n| Functions ||\n|------------------------------------------------------------------------------------------|-------------------------------|\n| [rsGetDt](/guide/topics/renderscript/reference/rs_time#android_rs:rsGetDt) | Elapsed time since last call |\n| [rsLocaltime](/guide/topics/renderscript/reference/rs_time#android_rs:rsLocaltime) | Convert to local time |\n| [rsTime](/guide/topics/renderscript/reference/rs_time#android_rs:rsTime) | Seconds since January 1, 1970 |\n| [rsUptimeMillis](/guide/topics/renderscript/reference/rs_time#android_rs:rsUptimeMillis) | System uptime in milliseconds |\n| [rsUptimeNanos](/guide/topics/renderscript/reference/rs_time#android_rs:rsUptimeNanos) | System uptime in nanoseconds |\n\nTypes\n-----\n\n#### rs_time_t\n: Seconds since January 1, 1970\n\nA typedef of: int When compiling for 32 bits.\n\nA typedef of: long When compiling for 64 bits.\n\nCalendar time interpreted as seconds elapsed since the Epoch (00:00:00 on\nJanuary 1, 1970, Coordinated Universal Time (UTC)). \n\n#### rs_tm\n: Date and time structure\n\nA structure with the following fields:\n\n| int tm_sec | Seconds after the minute. This ranges from 0 to 59, but possibly up to 60 for leap seconds. |\n| int tm_min | Minutes after the hour. This ranges from 0 to 59. |\n| int tm_hour | Hours past midnight. This ranges from 0 to 23. |\n| int tm_mday | Day of the month. This ranges from 1 to 31. |\n| int tm_mon | Months since January. This ranges from 0 to 11. |\n| int tm_year | Years since 1900. |\n| int tm_wday | Days since Sunday. This ranges from 0 to 6. |\n| int tm_yday | Days since January 1. This ranges from 0 to 365. |\n| int tm_isdst | Flag 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. |\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n\u003cbr /\u003e\n\nData structure for broken-down time components.\n\nFunctions\n---------\n\n#### rsGetDt\n: Elapsed time since last call\n\n|------------------|---|\n| float rsGetDt(); | |\n\n##### Returns\n\n|------------------|\n| Time in seconds. |\n\nReturns the time in seconds since this function was last called in this script. \n\n#### rsLocaltime\n: Convert to local time\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [rs_tm](/guide/topics/renderscript/reference/rs_time#android_rs:rs_tm)\\* rsLocaltime([rs_tm](/guide/topics/renderscript/reference/rs_time#android_rs:rs_tm)\\* local, const [rs_time_t](/guide/topics/renderscript/reference/rs_time#android_rs:rs_time_t)\\* timer); | |\n\n##### Parameters\n\n| local | Pointer to time structure where the local time will be stored. |\n| timer | Input time as a number of seconds since January 1, 1970. |\n|-------|----------------------------------------------------------------|\n\n##### Returns\n\n|-------------------------------------------------------------------------------|\n| Pointer to the output local time, i.e. the same value as the parameter local. |\n\nConverts the time specified by timer into a [rs_tm](/guide/topics/renderscript/reference/rs_time#android_rs:rs_tm) structure that provides year, month,\nhour, etc. This value is stored at \\*local.\n\nThis functions returns the same pointer that is passed as first argument. If the\nlocal parameter is NULL, this function does nothing and returns NULL. \n\n#### rsTime\n: Seconds since January 1, 1970\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [rs_time_t](/guide/topics/renderscript/reference/rs_time#android_rs:rs_time_t) rsTime([rs_time_t](/guide/topics/renderscript/reference/rs_time#android_rs:rs_time_t)\\* timer); | |\n\n##### Parameters\n\n| timer | Location to also store the returned calendar time. |\n|-------|----------------------------------------------------|\n\n##### Returns\n\n|--------------------------------------------------|\n| Seconds since the Epoch, -1 if there's an error. |\n\nReturns the number of seconds since the Epoch (00:00:00 UTC, January 1, 1970).\n\nIf timer is non-NULL, the result is also stored in the memory pointed to by\nthis variable. \n\n#### rsUptimeMillis\n: System uptime in milliseconds\n\n|-----------------------------------------------------------------------------------------------------|---|\n| [int64_t](/guide/topics/renderscript/reference/rs_value_types#android_rs:int64_t) rsUptimeMillis(); | |\n\n##### Returns\n\n|-------------------------|\n| Uptime in milliseconds. |\n\nReturns the current system clock (uptime) in milliseconds. \n\n#### rsUptimeNanos\n: System uptime in nanoseconds\n\n|----------------------------------------------------------------------------------------------------|---|\n| [int64_t](/guide/topics/renderscript/reference/rs_value_types#android_rs:int64_t) rsUptimeNanos(); | |\n\n##### Returns\n\n|------------------------|\n| Uptime in nanoseconds. |\n\nReturns the current system clock (uptime) in nanoseconds.\n\nThe granularity of the values return by this call may be much larger than a nanosecond."]]