系统时间函数TIME()的类型是什么啊···急用

系统时间函数TIME()的类型是什么啊···急用,第1张

time_t time( time_t timer );

/ TIMESC illustrates various time and date functions including:

time _ftime ctime asctime

localtime gmtime mktime _tzset

_strtime _strdate strftime

Also the global variable:

_tzname

/

#include <timeh>

#include <stdioh>

#include <sys/typesh>

#include <sys/timebh>

#include <stringh>

void main()

{

char tmpbuf[128], ampm[] = "AM";

time_t ltime;

struct _timeb tstruct;

struct tm today, gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/ Set time zone from TZ environment variable If TZ is not set,

the operating system is queried to obtain the default value

for the variable

/

_tzset();

/ Display operating system-style date and time /

_strtime( tmpbuf );

printf( "OS time:\t\t\t\t%s\n", tmpbuf );

_strdate( tmpbuf );

printf( "OS date:\t\t\t\t%s\n", tmpbuf );

/ Get UNIX-style time and display as number and string /

time( &ltime );

printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );

printf( "UNIX time and date:\t\t\t%s", ctime( &ltime ) );

/ Display UTC /

gmt = gmtime( &ltime );

printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

/ Convert to time structure and adjust for PM if necessary /

today = localtime( &ltime );

if( today->tm_hour > 12 )

{

strcpy( ampm, "PM" );

today->tm_hour -= 12;

}

if( today->tm_hour == 0 ) / Adjust if midnight hour /

today->tm_hour = 12;

/ Note how pointer addition is used to skip the first 11

characters and printf is used to trim off terminating

characters

/

printf( "12-hour time:\t\t\t\t%8s %s\n",

asctime( today ) + 11, ampm );

/ Print additional time information /

_ftime( &tstruct );

printf( "Plus milliseconds:\t\t\t%u\n", tstructmillitm );

printf( "Zone difference in seconds from UTC:\t%u\n",

tstructtimezone );

printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );

printf( "Daylight savings:\t\t\t%s\n",

tstructdstflag "YES" : "NO" );

/ Make time for noon on Christmas, 1993 /

if( mktime( &xmas ) != (time_t)-1 )

printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

/ Use time structure to build a customized time string /

today = localtime( &ltime );

/ Use strftime to build a customized time string /

strftime( tmpbuf, 128,

"Today is %A, day %d of %B in the year %Y\n", today );

printf( tmpbuf );

}

#include<timeh>

int main()

{

time_t timep;

struct tm p;

time (&timep);

p=gmtime(&timep);

printf("%d\n",p->tm_sec); /获取当前秒/

printf("%d\n",p->tm_min); /获取当前分/

printf("%d\n",8+p->tm_hour);/获取当前时,这里获取西方的时间,刚好相差八个小时/

printf("%d\n",p->tm_mday);/获取当前月份日数,范围是1-31/

printf("%d\n",1+p->tm_mon);/获取当前月份,范围是0-11,所以要加1/

printf("%d\n",1900+p->tm_year);/获取当前年份,从1900开始,所以要加1900/

printf("%d\n",p->tm_yday); /从今年1月1日算起至今的天数,范围为0-365/

}

C语言是一门通用计算机编程语言,广泛应用于底层开发。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。

尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。

二十世纪八十年代,为了避免各开发厂商用的C语言语法产生差异,由美国国家标准局为C语言制定了一套完整的美国国家标准语法,称为ANSI C,作为C语言最初的标准。目前2011年12月8日,国际标准化组织(ISO)和国际电工委员会(IEC)发布的C11标准是C语言的第三个官方标准,也是C语言的最新标准,该标准更好的支持了汉字函数名和汉字标识符,一定程度上实现了汉字编程。

C语言是一门面向过程的计算机编程语言,与C++,Java等面向对象的编程语言有所不同。

其编译器主要有Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C等。

参考资料:

C语言_

1.系统日期函数DATE( )

格式DATE()

功能返回当前系统日期,此日期由Windows系统设置。函数值为D型。

2.系统时间函数TIME( )

格式TIME([<nExp>])

功能返回当前系统时间,时间显示格式为hh:mm:ss。若选择了nExp ,则不管为何值,返回的系统时间还包括秒的小数部分,精确至小数点后两位。函数值为C型。

3.日期函数DAY( )

格式DAY(<dExp>)

功能返回dExp式中的天数。函数值为N型

4.星期函数DOW( )、CDOW( )

格式DOW(<dExp>)

CDOW(<dExp>)

功能DOW( )函数返回dExp式中星期的数值,用1~7表示星期日~星期六。函数值为N型。CDOW( )函数返回dExp式中星期的英文名称。函数值为C型。

5.月份函数MONTH( )、CMONTH( )

格式MONTH(<dExp>)

CMONTH(<dExp>)

功能MONTH( )函数返回dExp式中月份数。函数值为N型。CMONTH( )函数则返回月份的英文名。函数值为C型。

6.年份函数YEAR( )

格式YEAR(<dExp>)

功能函数返回dExp式中年份值。函数值为N型。

#include <stdioh>

#include <timeh>

int main()

{

time_t timep; //时间变量,从1970年1月1日0时起的秒数

struct tm p; //时间结构,含年月日时分秒星期几,一年中第几天,夏时制等成员。年从1900起算,月从0起算,

time(&timep); // 获取当前时间,从1970年1月1日0时起的秒数

p = gmtime(&timep); // 获取UTC时间 结构成员数值们

printf("%d %d %d\n",1900+p->tm_year, 1+p->tm_mon, p->tm_mday); //输出UTC时间的年月日

p = localtime(&timep); // 获取本地 时间 结构成员数值们

printf("%d %d %d\n",1900+p->tm_year, 1+p->tm_mon, p->tm_mday); //输出本地时间年月日

return 0;

}

头文件timeh \x0d\\x0d\@函数名称: localtime \x0d\函数原型: struct tm localtime(const time_t timer) \x0d\函数功能: 返回一个以tm结构表达的机器时间信息 \x0d\函数返回: 以tm结构表达的时间,结构tm定义如下: \x0d\struct tm{ \x0d\ int tm_sec; \x0d\ int tm_min; \x0d\ int tm_hour; \x0d\ int tm_mday; \x0d\ int tm_mon; \x0d\ int tm_year; \x0d\ int tm_wday; \x0d\ int tm_yday; \x0d\ int tm_isdst; \x0d\ }; \x0d\参数说明: timer-使用time()函数获得的机器时间 \x0d\\x0d\#include \x0d\#include \x0d\#include \x0d\int main() \x0d\{ \x0d\ time_t timer; \x0d\ struct tm tblock; \x0d\ timer=time(NULL); \x0d\ tblock=localtime(&timer); \x0d\ printf("Local time is: %s",asctime(tblock)); \x0d\ return 0; \x0d\} \x0d\\x0d\@函数名称: asctime \x0d\函数原型: char asctime(struct tm ptr) \x0d\函数功能: 得到机器时间(日期时间转换为ASCII码) \x0d\函数返回: 返回的时间字符串格式为:星期,月,日,小时:分:秒,年 \x0d\参数说明: 结构指针ptr应通过函数localtime()和gmtime()得到 \x0d\所属文件: \x0d\\x0d\#include \x0d\#include \x0d\#include \x0d\int main() \x0d\{ \x0d\ struct tm t; \x0d\ char str[80]; \x0d\ ttm_sec=1; \x0d\ ttm_min=3; \x0d\ ttm_hour=7; \x0d\ ttm_mday=22; \x0d\ ttm_mon=11; \x0d\ ttm_year=56; \x0d\ ttm_wday=4; \x0d\ ttm_yday=0; \x0d\ ttm_isdst=0; \x0d\ strcpy(str,asctime(&t)); \x0d\ printf("%s",str); \x0d\ return 0; \x0d\} \x0d\\x0d\@函数名称: ctime \x0d\函数原型: char ctime(long time) \x0d\函数功能: 得到日历时间 \x0d\函数返回: 返回字符串格式:星期,月,日,小时:分:秒,年 \x0d\参数说明: time-该参数应由函数time获得 \x0d\所属文件: \x0d\\x0d\#include \x0d\#include \x0d\int main() \x0d\{ \x0d\ time_t t; \x0d\ time(&t); \x0d\ printf("Today's date and time: %s",ctime(&t)); \x0d\ return 0; \x0d\} \x0d\\x0d\@函数名称: difftime \x0d\函数原型: double difftime(time_t time2, time_t time1) \x0d\函数功能: 得到两次机器时间差,单位为秒 \x0d\函数返回: 时间差,单位为秒 \x0d\参数说明: time1-机器时间一,time2-机器时间二该参数应使用time函数获得 \x0d\所属文件: \x0d\\x0d\#include \x0d\#include \x0d\#include \x0d\#include \x0d\int main() \x0d\{ \x0d\ time_t first, second; \x0d\ clrscr(); \x0d\ first=time(NULL); \x0d\ delay(2000); \x0d\ second=time(NULL); \x0d\ printf("The difference is: %f seconds",difftime(second,first)); \x0d\ getch(); \x0d\ return 0; \x0d\} \x0d\\x0d\@函数名称: gmtime \x0d\函数原型: struct tm gmtime(time_t time) \x0d\函数功能: 得到以结构tm表示的时间信息 \x0d\函数返回: 以结构tm表示的时间信息指针 \x0d\参数说明: time-用函数time()得到的时间信息 \x0d\所属文件: \x0d\\x0d\#include \x0d\#include \x0d\#include \x0d\#include \x0d\char tzstr="TZ=PST8PDT"; \x0d\int main() \x0d\{ \x0d\ time_t t; \x0d\ struct tm gmt, area; \x0d\ putenv(tzstr); \x0d\ tzset(); \x0d\ t=time(NULL); \x0d\ area=localtime(&t); \x0d\ printf("Local time is:%s", asctime(area)); \x0d\ gmt=gmtime(&t); \x0d\ printf("GMT is:%s", asctime(gmt)); \x0d\ return 0; \x0d\} \x0d\\x0d\@函数名称: time \x0d\函数原型: time_t time(time_t timer) \x0d\函数功能: 得到机器的日历时间或者设置日历时间 \x0d\函数返回: 机器日历时间 \x0d\参数说明: timer=NULL时得到机器日历时间,timer=时间数值时,用于设置日历时间,time_t是一个long类型 \x0d\所属文件: \x0d\\x0d\#include \x0d\#include \x0d\#include \x0d\int main() \x0d\{ \x0d\ time_t t; \x0d\ t=time(); \x0d\ printf("The number of seconds since January 1,1970 is %ld",t); \x0d\ return 0; \x0d\} \x0d\\x0d\@函数名称: tzset \x0d\函数原型: void tzset(void) \x0d\函数功能: UNIX兼容函数,用于得到时区,在DOS环境下无用途 \x0d\函数返回: \x0d\参数说明: \x0d\所属文件: \x0d\\x0d\#include \x0d\#include \x0d\#include \x0d\int main() \x0d\{ \x0d\ time_t td; \x0d\ putenv("TZ=PST8PDT"); \x0d\ tzset(); \x0d\ time(&td); \x0d\ printf("Current time=%s",asctime(localtime(&td))); \x0d\ return 0; \x0d\}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/12157625.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-21
下一篇2023-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存