Android 所用C/C++庫Bionic API. 即輕量級C/C++庫. 分32位同64位, 32位『time_t』有效期至2038年, 64位『__time64_t』有效期至3000年.
呌『tm』時間結構
struct tm { | 結構時間 |
int tm_sec; | 秒鐘[0~59] |
int tm_min; | 分鐘[0~59] |
int tm_hour; | 時鐘[0~23] |
int tm_mday; | 號[1~31] |
int tm_mon; | 月份[0~11] 需加1 |
int tm_year; | 年份需加1900, 儒略歴 |
int tm_wday; | 禮拜[0~1],禮拜日Sunday=0 |
int tm_yday; | 天[0~365],1月1號=0 |
int tm_isdst; | 夏令時為正, 否 |
long int tm_gmtoff; | 當前時相對UTC往東時差,即東爲正西爲負. |
const char* tm_zone;}; | 時區縮寫 |
係『Win32 API』你需time()/_time64()獲得時間, 再蒞localtime()/_localtime64()根據時區轉爲本地時間『tm』
Win32 API版本 |
char time_text[280];
struct tm temp_str;// 時間結构 __time64_t temp_int;// 時間整数 _time64(&temp_int);// 获取時間 _localtime64_s(&temp_str ,&temp_int);// 根据時區轉為本地時間 sprintf(time_text, “%4d-%02d-%02d %02d:%02d:%02d”, 1900+temp_str.tm_year,1+temp_str.tm_mon, temp_str.tm_mday, temp_str.tm_hour,temp_str.tm_min,temp_str.tm_sec); |
2021-09-09 23:43:08 |
Android Studio NDK 『Bionic API』版本,可用localtime_r()根據時區獲得本地時間『tm』
Bionic API版本 |
char time_text[280];// 時間文本
struct tm temp_str;// 時間結構 time_t temp_int;// 32位時間整數 temp_int = time(0); localtime_r(&temp_int,&temp_str);// 根據時區轉爲本地時間 sprintf(time_text, “%04d-%02d-%02d %02d:%02d:%02d”, 1900+temp_str.tm_year,1+temp_str.tm_mon, temp_str.tm_mday, temp_str.tm_hour,temp_str.tm_min,temp_str.tm_sec); |
2021-09-09 23:43:08 |