如何调用安卓的系统时间?
c4droid吧
全部回复
仅看楼主
level 3
wondows下可以用windows.h,那android下呢?[呵呵]
2016年12月17日 12点12分 1
level 12
获取系统时间代码:(使用g++编译器)
#include<iostream>
#include<chrono>
#include<string>
//#define CLEAR() printf("\033[2J")
const std::string gtime( ) //将系统时间转为string字符串
{
auto tt = std::chrono::system_clock::to_time_t
(std::chrono::system_clock::now());
struct tm* ptm = localtime(&tt);
char date[60] = {0};
sprintf(date, "%d-%02d-%02d %02d:%02d:%02d",
(int)ptm->tm_year + 1900,(int)ptm->tm_mon + 1,(int)ptm->tm_mday,
(int)ptm->tm_hour,(int)ptm->tm_min,(int)ptm->tm_sec);
return std::string(date);
}
int main( )
{
std::cout << gtime ( ) << '\n';
return 0;
}
2016年12月17日 23点12分 3
chrono是什么头文件
2016年12月18日 00点12分
level 12
time.h
time();
2016年12月18日 01点12分 4
level 10
time.h/ctime的std::time
或者chrono(C++11)的std::chrono::system_clock::now
2016年12月18日 18点12分 5
1