当前位置: 技术问答>linux和unix
Linux 怎样得到系统时间
来源: 互联网 发布时间:2014-12-13
本文导语: Linux中或标准C中怎样得到系统时间,他的定义类型是什么? | #include #include #include int main() { struct tm *pTime; time_t nNow; /*距1970年1月1日0小时0分0秒的秒数*/ time...
Linux中或标准C中怎样得到系统时间,他的定义类型是什么?
|
#include
#include
#include
int main()
{
struct tm *pTime;
time_t nNow; /*距1970年1月1日0小时0分0秒的秒数*/
time( &nNow ); /* 取UTC时间 */
pTime = localtime( &nNow ); /* 将UTC时间转换成本时区的时间 */
printf ( "小时:%02d 分:%02d, 秒:%02dn",pTime->tm_hour, pTime->tm_min, pTime->tm_sec );
return(0);
}
其中struct tm 如下
struct tm {
int tm_sec; /* seconds after the minute -- [0, 61] */
/* 60 and 61 for leap seconds */
int tm_min; /* minutes after the hour -- [0, 59] */
int tm_hour; /* hour since midnight -- [0, 23] */
int tm_mday; /* day of the month -- [1, 31] */
int tm_mon; /* months since January -- [0, 11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday -- [0, 6] */
int tm_yday; /* days since January 1 -- [0, 365] */
int tm_isdst; /* flag for daylight savings time */
long tm_tzadj; /* seconds from UTC (east
#include
#include
int main()
{
struct tm *pTime;
time_t nNow; /*距1970年1月1日0小时0分0秒的秒数*/
time( &nNow ); /* 取UTC时间 */
pTime = localtime( &nNow ); /* 将UTC时间转换成本时区的时间 */
printf ( "小时:%02d 分:%02d, 秒:%02dn",pTime->tm_hour, pTime->tm_min, pTime->tm_sec );
return(0);
}
其中struct tm 如下
struct tm {
int tm_sec; /* seconds after the minute -- [0, 61] */
/* 60 and 61 for leap seconds */
int tm_min; /* minutes after the hour -- [0, 59] */
int tm_hour; /* hour since midnight -- [0, 23] */
int tm_mday; /* day of the month -- [1, 31] */
int tm_mon; /* months since January -- [0, 11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday -- [0, 6] */
int tm_yday; /* days since January 1 -- [0, 365] */
int tm_isdst; /* flag for daylight savings time */
long tm_tzadj; /* seconds from UTC (east