码迷,mamicode.com
首页 > 移动开发 > 详细

android开发:jni下native代码获取毫秒级时间

时间:2015-01-27 18:05:02      阅读:1600      评论:0      收藏:0      [点我收藏+]

标签:

#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 = 1327656212666
usec_d = 838745, usec_ld = 838745, usec_lld = 1327656212666
now_d = 338605759, now_ld = 511318374, now_ld = 1327656212838 (正确结果)
sizeof(int) = 4
sizeof(long) = 4
sizeof(long long) = 8

 

 

 

android开发:jni下native代码获取毫秒级时间

标签:

原文地址:http://www.cnblogs.com/VincentLEcho/p/4253540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!