linux c 时间函数
1、 time() 函数提供了 秒 级的精确度
time_t time(time_t * timer)
函数返回从UTC1970-1-1 0:0:0开始到现在的秒数
2、 struct timespec 提供了 ns 级的精确度
定义如下:
typedef long time_t;
#ifndef _TIMESPEC
#define _TIMESPEC
struct timespec {
time_t tv_sec; // seconds
long tv_nsec; // and nanoseconds
};
#endif
对应的操作函数为
int clock_gettime(clockid_t, struct timespec *)
其中 clockid_t 为使用的时钟,主要有以下四种:
CLOCK_REALTIME 统当前时间,从1970年1.1日算起
CLOCK_MONOTONIC 系统的启动时间,不能被设置
CLOCK_PROCESS_CPUTIME_ID 本进程运行时间
CLOCK_THREAD_CPUTIME_ID 本线程运行时间
3、struct timeval 提供了 us 级 的精确度
struct timeval {
time_t tv_sec; // seconds
long tv_usec; // microseconds
};
对应的操作函数为
int gettimeofday(struct timeval *tv, struct timezone *tz)
其中 timezone 为时区,定义如下:
struct timezone{
int tz_minuteswest; //miniutes west of Greenwich
int tz_dsttime; //type of DST correction
};
一般时区填写为 NULL即可。
linux c 时间函数的更多相关文章
- linux中时间函数
linux下常用时间类型有四种: time_t . struct tm. struct timeval . struct timespec 1.time_t 时间函数 time_t ...
- Unix/Linux系统时间函数API
首先说明关于几个时间的概念: 世界时:起初,国际上的标准时间是格林尼治标准时间,以太阳横穿本初子午线的时刻为标准时间正午12点.它根据天文环境来定义,就像古代人们根据日晷来计时一样,如下图: 原子时: ...
- Linux系统时间函数
先来说说自己在做工程过程中的一些理解: 1, 输入time_t,输出tm格式的函数 loctaltime(time_t) / gmtime(time_t) 其中localtime会受时区和夏令时影响, ...
- Linux常用时间函数
time()函数: NAME time - get time in seconds SYNOPSIS #include <time.h> time_t time(time_t *tloc) ...
- 基于Linux整形时间的常用计算思路
上一次分享了Linux时间时区详解与常用时间函数,相信大家对Linux常见时间函数的使用也有了一定的了解,在工作中遇到类似获取时间等需求的时候也一定能很好的处理.本文基于Linux整形时间给出一些简化 ...
- Linux时间函数之gettimeofday()函数之使用方法
1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...
- 【转】Linux时间函数之gettimeofday()函数之使用方法
原文网址:http://blog.csdn.net/tigerjibo/article/details/7039434 一.gettimeofday()函数的使用方法: 1.简介: 在C语言中可以使用 ...
- linux几种时间函数总结
一.linux时间函数总结 最近的工作中用到的时间函数比较频繁,今天抽时间总结一下,在linux下,常用的获取时间的函数有如下几个: asctime, ctime, gmtime, localti ...
- Linux下系统时间函数、DST等相关问题总结(转)
Linux下系统时间函数.DST等相关问题总结 下面这个结构体存储了跟时区相关的位移量(offset)以及是否存在DST等信息,根据所在的时区信息,很容易找到系统时间与UTC时间之间的时区偏移,另外根 ...
随机推荐
- 来自Composer中文网安装composer指南
如果有需要安装composer的童鞋可以参考这个文章配置自己的composer https://pkg.phpcomposer.com/#how-to-install-composer 这里可能会出很 ...
- [Android] Android 注解绑定UI View组件库 ButterKnife 的使用
ButterKnife是一个专注于Android系统的View注入框架,以前总是要写很多findViewById来找到View对象,有了ButterKnife可以很轻松的省去这些步骤.是大神JakeW ...
- 解析/proc/net/dev
https://stackoverflow.com/questions/1052589/how-can-i-parse-the-output-of-proc-net-dev-into-keyvalue ...
- Silverlight中字典的使用
通过值搜索字典中的项: FristOfDefault返回序列中满足条件的第一个元素:如果未找到这样的元素,则返回默认值.
- 搭建VirtualBox虚拟机集群
===============================VirtualBox常用网络===============================NetworkAddress Translati ...
- Dictionary与SortedDictionary
Dictionary是无序的,如果想排序,需要使用SortDictionary. 下面是一个用法示例 //按照某个字段排序 public void SortByCardItem(string item ...
- java8 新特性 Optional容器类
public class Godness { private String name; public Godness() { } public Godness(String name) { this. ...
- Android adb shell 常用命令
Ø 简介 adb 命令是 Android SDK 中自带的一个调试工具,可以调试电脑中的手机或者模拟器,使用 adb 命令前需要将 sdk 中的 platform-tools 目录添加到环境变量中. ...
- 代码管理工具:使用github和git工具管理自己的代码
一.git工具和账户创建 1.1 安装 Git 是 Linus Torvalds 最近实现的源代码管理软件."Git 是一个快速.可扩展的分布式版本控制系统,它具有极为丰富的命令集,对内部系 ...
- loj 6436 PKUSC2018 神仙的游戏
传送门 好妙蛙 即串\(s\)长度为\(n\)首先考虑如果一个长度为\(len\)的\(border\)存在,当且仅当对所有\(i\in[1,len],s[i]=s[n-len+i]\),也就是所有模 ...