现在的位置: 首页 > 综合 > 正文

Linux下time/timestamp相关。

2013年09月07日 ⁄ 综合 ⁄ 共 1829字 ⁄ 字号 评论关闭

 在Linux下面编程,经常要碰到用到与time/timestamp相关的东西,下面是我以前收集的,放在这里共享。

 

In the file: dbus-sysdeps-unix.c



/**

 * Get current time, as in gettimeofday().

 *

 * @param tv_sec return location for number of seconds

 * @param tv_usec return location for number of microseconds (thousandths)

 */

void

_dbus_get_current_time (long *tv_sec,

                        long *tv_usec)

{

  struct timeval t;

 

  gettimeofday (&t, NULL);

 

  if (tv_sec)

    *tv_sec = t.tv_sec;

  if (tv_usec)

    *tv_usec = t.tv_usec;

}

 

 

How to use it:

 

 

 



/**

 * Get current time, as in gettimeofday().

 *

 * @param tv_sec return location for number of seconds

 * @param tv_usec return location for number of microseconds (thousandths)

 */

void

_dbus_get_current_time (long *tv_sec,

                        long *tv_usec)

{

  struct timeval t;

 

  gettimeofday (&t, NULL);

 

  if (tv_sec)

    *tv_sec = t.tv_sec;

  if (tv_usec)

    *tv_usec = t.tv_usec;

}

 

 

Two time structures:

 

Struct timeval:

  struct   timeval  
  {  
          long   tv_sec;  
          long   tv_usec;  
  }  

 

 

 

 

 

 

 


 

14.11 我知道 localtime() 可以把 time_t 转换结构  struct tm,  ctime() 可以把 time_t 转换可打印的字符串。才能行反向操作,  struct tm 或一字符串转换 time_t

ANSI C 提供了 mktime(),  struct tm 转换 time_t

把一字符串转换 time_t 较难, 是由于可能遇到各的日期和时间格式。某些系提供函 strptime(), 基本上是 strftime()  的反向函。其常用的函 partime() ( RCS 包一起被广泛的 getdate() (有少, 布在 C 的新闻组)见问题  18.18

 

 

C/C++中的日期和时间 time_t(cjp: long)struct tm

2006-07-18 14:07

摘要:

http://wiseman.cnblogs.com
本文础概念入手,探了在C/C++日期和时间操作所用到的结构和函对计时时间取、时间算和示格式等方面行了述。本文大量的例向展示了time.h文件中明的各结构详细使用方法。

关键字:UTC(世界时间),Calendar Time(日历时间),epoch时间点),clock tick时钟计时单元)

1
C/C++中,字符串的操作有很多得注意的问题,同C/C++对时间的操作也有得大家注意的地方。最近,在技群中有很多友也多次C++言中对时间的操作、取和示等等的问题。下面,在篇文章中,主要介C/C++时间和日期的使用方法.

过学习许C/C++可以有很多操作、使用时间的方法。但在之前需要了解一些时间日期念,主要有以下几

Coordinated Universal TimeUTC):协调世界,又世界时间,也就是大家所熟知的格林威治时间Greenwich Mean TimeGMT)。比如,中国内地的时间与UTC+8,也就是UTC+8。美UTC-5

Calendar Time:日历时间,是用时间

抱歉!评论已关闭.