Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2691491
  • 博文数量: 505
  • 博客积分: 1552
  • 博客等级: 上尉
  • 技术积分: 2514
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-23 18:24
文章分类

全部博文(505)

文章存档

2019年(12)

2018年(15)

2017年(1)

2016年(17)

2015年(14)

2014年(93)

2013年(233)

2012年(108)

2011年(1)

2009年(11)

分类: 嵌入式

2015-12-05 16:43:25

android 中得到1970到现在的时间:
在JAVA中可以通过System.currentTimeMillis()得到:
long start_time = System.currentTimeMillis();
View.draw(canvas);
long end_time = System.currentTimeMillis();
long spend_time = end_time - start_time;
Log.i(TAG,"mView.draw: spend_time = " + spend_time);

android 的C/C++中,下面的例子得到:
#include "time.h"
#include
void main ()
{
    time_t rawtime;
    struct tm * timeinfo;
    time ( &rawtime );得到的是秒,悲剧了,不对称呀
    printf ( "\007The current date/time is: %ld\n", rawtime );
}
得到的是秒,悲剧了,跟JAVA对应不起来,换个方式吧!

找个半天,结果找到了下面的方式:
#include
#include
void main ()
{
    struct timeval time;
    gettimeofday(&time, NULL);
    printf ( "\007The current date/time is:  %lld\n", time.tv_sec * 1000 + time.tv_usec /1000);
}
这样得到的才是毫秒,真折腾。其中timeval的tv_sec是秒,tv_usec微秒。

android 的C/C++中打LOG
得到了时间,如何在C/C++中打LOG呢?有下面的方式。
#include
LOGW("the end of android_view_ViewRoot_showFPS, dur: %d", dur);
__android_log_write(ANDROID_LOG_VERBOSE,"ViewRoot","the end of android_view_ViewRoot_showFPS");
阅读(2965) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~