LINUX系统编程之日历时间
LINUX中时间有两种:
1)日历时间
2)进程时间
日历时间顾名思义即用来获取日历;
主要涉及到的函数有:
time(time_t*);
stime(time_t*);
tm* gmtime(time_t*);
tm* localtime(time_t*);
char *strftime(tm*);
char *asctime(tm*);
time_t* mktime(tm*);
数据结构如下:
time_t
struct tm{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_wday;
int tm_yday;
int tm_year;
int tm_isdst;
}
转换关系如下图:
示例代码如下:
struct utsname aname;
int a=uname(&aname);
cout << a;
cout << endl;
cout << aname.sysname<< endl;
cout << aname.machine<< endl;
cout << aname.release<< endl;
cout << aname.version<<endl;
cout << aname.nodename<< endl;
time_t time1;
time_t time2;
time2=time(&time1);
cout << time1 << endl;
cout << time2 << endl;
struct tm *tm1;
tm1=localtime(&time1);
cout << tm1->tm_sec<<endl;
cout << tm1->tm_min<<endl;
cout << tm1->tm_hour<<endl;
cout << tm1->tm_mday<<endl;
cout << tm1->tm_mon<<endl;
cout << tm1->tm_year<<endl;
cout << tm1->tm_wday<<endl;
cout << tm1->tm_yday<<endl;
char *css;
css=asctime(tm1);
cout << css;
size_t size=strftime(css,100,"%Y-%m-%d %H-%M-%S %w",tm1);
cout << size << ":"<<css;
相关文档:
2009 年 4 月 23 日
本文中我们针对 Linux 上多线程编程的主要特性总结出 5 条经验,用以改善 Linux 多线程编程的习惯和避免其中的开发陷阱。在本文中,我们穿插一些 Windows 的编程用例用以对比 Linux 特性,以加深读者印象。
背景
Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多线程 API 有一些细微 ......
当Linux内核在体系结构差异较大的平台之间移植时,会产生与数据类型相关的问题。
.在编译内核时使用 -Wall -W strict-prototypes 选项, 可以避免很多错误的发生
.内核使用的基本数据类型主要有:
int 标准C语言整数类型
&n ......
以下是本人在学习linux编程时查找并整理的一些东西,与大家分享:
Vi大家都很熟悉,某些情况下它是我们在Linux下唯一可用的文本编辑器。其实我们平时所指的VI其实是VIM(ViImproved,VI增强版)。有人常常拿VIM和emacs比较,VIM尽管不象emacs那样有那么多的功能,但是比emacs更方便、好用。VIM简单易用,只要看看V ......
1.
linux
命令的调试使用
以下是从网上查找来的
linux
命令
zip
的使用方法。如果有不知道命令如何使用你可以
man+[
命令
]
或者是
[
命令
]+
“
-h
”,来查看命令的使用方法。
zip
功能说明:压缩文件。
语 法:
zip
[-AcdDfFghj ......
vi 中关闭出错 bell 声音
http://blog.csdn.net/coolrocky/archive/2001/06/05/8080.aspx
去除虚拟机Linux的报警声
http://hi.baidu.com/zjd168/blog/item/c8300846b5a6ec0e6a63e5d8.html
关闭主板报警音
http://linux.chinaunix.net/techdoc/install/2009/05/16/1112897.shtml
linux中关闭报警音和修改分辨率
http ......