Linux获取系统当前时间(精确到毫秒)
2015-11-25 17:15
609 查看
#include <stdio.h> #include <time.h> #include <sys/time.h> void sysLocalTime(void) { time_t timesec; struct tm *t; time(×ec); t = localtime(×ec); printf("%d-%d-%d %d:%d:%d\n", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } void sysUsecTime(void) { struct timeval tv; struct timezone tz; struct tm *t; gettimeofday(&tv, &tz); printf("tv_sec:%ld\n",tv.tv_sec); printf("tv_usec:%ld\n",tv.tv_usec); printf("tz_minuteswest:%d\n",tz.tz_minuteswest); printf("tz_dsttime:%d\n",tz.tz_dsttime); t = localtime(&tv.tv_sec); printf("time_now:%d-%d-%d %d:%d:%d.%ld\n", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec); } int main(void) { sysLocalTime(); sysUsecTime(); return 0; }
相关文章推荐
- Centos7 Lnmp Laravel
- 理解Linux系统负荷
- CentOS安装Subversion 1.9.*版本客户端
- Linux中只列出目录
- Linux下查看文件和文件夹大小
- Linux系统设置定时任务
- VIM入门配置
- CentOS 6 安装epel源
- 虚拟机linux与主机时间同步
- Linux下修改Mysql的用户(root)的密码
- PYTHON多进程并发WEB服务器(利用LINUX的FORK)
- Linux下发包处理
- linux下 查看外网IP命令
- CentOS下修复grub引导程序
- 误卸载linux自带的rpm包
- Linux上vi(vim)编辑器使用教程
- linux 查看文件夹大小
- linux下的mysql乱码问题
- Linux下 RabbitMQ的安装与配置
- 全面解析Linux 内核 3.10.x - Device Tree 详解