首页 > 代码库 > android开发:jni下native代码获取毫秒级时间
android开发:jni下native代码获取毫秒级时间
#include <android/log.h>#define LOG_TAG ""#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)struct timeval xTime;int xRet = gettimeofday(&xTime, NULL);long long xFactor = 1;long long now = (long long)(( xFactor * xTime.tv_sec * 1000) + (xTime.tv_usec / 1000));LOGD("sec_d = %d, sec_ld = %ld, sec_lld = %lld\n", xTime.tv_sec, xTime.tv_sec, xTime.tv_sec);LOGD("usec_d = %d, usec_ld = %ld, usec_lld = %lld\n", xTime.tv_usec, xTime.tv_usec, xTime.tv_usec);LOGD("now_d = %d, now_ld = %ld, now_ld = %lld\n", now, now, now);LOGD("sizeof(int) = %d\n", sizeof(int));LOGD("sizeof(long) = %d\n", sizeof(long));LOGD("sizeof(long long) = %d\n", sizeof(long long));
输出为:
sec_d = 1327656212, sec_ld = 1327656212, sec_lld = 1327656212666usec_d = 838745, usec_ld = 838745, usec_lld = 1327656212666now_d = 338605759, now_ld = 511318374, now_ld = 1327656212838 (正确结果)
sizeof(int) = 4sizeof(long) = 4sizeof(long long) = 8
android开发:jni下native代码获取毫秒级时间
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。