TIMES.C
来源:互联网 发布:js json remove key 编辑:程序博客网 时间:2024/05/19 02:19
/* TIMES.C illustrates various time and date functions including: * time _ftime ctime asctime * localtime gmtime mktime _tzset * _strtime _strdate strftime * * Also the global variable: * _tzname */#include <time.h>#include <stdio.h>#include <sys/types.h>#include <sys/timeb.h>#include <string.h>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( <ime ); printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime ); printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) ); /* Display UTC. */ gmt = gmtime( <ime ); printf( "Coordinated universal time:\t\t%s", asctime( gmt ) ); /* Convert to time structure and adjust for PM if necessary. */ today = localtime( <ime ); 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", tstruct.millitm ); printf( "Zone difference in seconds from UTC:\t%u\n", tstruct.timezone ); printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); printf( "Daylight savings:\t\t\t%s\n", tstruct.dstflag ? "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( <ime ); /* 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 );}
Output
OS time: 21:51:03OS date: 05/03/94Time in seconds since UTC 1/1/70: 768027063UNIX time and date: Tue May 03 21:51:03 1994Coordinated universal time: Wed May 04 04:51:03 199412-hour time: 09:51:03 PMPlus milliseconds: 279Zone difference in seconds from UTC: 480Time zone name: Daylight savings: YESChristmas Sat Dec 25 12:00:00 1993Today is Tuesday, day 03 of May in the year 1994.
- TIMES.C
- Our times
- This times
- request times
- Python Times
- times函数
- Work with dates and times(C和C++程序设计中使用日期和时间)
- Paradox Of Our Times
- Oracle Dates and Times
- My Second Times!
- My 3rd Times!
- My 4th Times!
- My 5th Times!
- My 6th Times!
- My 7th Times!
- [DirectShow] 021 - Clock Times
- Paradox of our times
- jQuery Times 计时器插件
- dell 笔记本开始时系统安装不上,在使用光驱的情况下。
- 有关手机软件的网址
- 14 架构设计要平衡兼顾多方需求
- 硬盘或移动硬盘被重新分区后,数据怎么恢复
- UVa 439 Knight Moves (bfs)
- TIMES.C
- 你还在为你的妹子奋斗么
- 调整心态,走上百万富翁之路
- position
- apache和tomcat整合连接插件下载地址
- u Calculate e解题报告
- switch case 疑点解析
- initialization of xxx is skipped by xxx
- 腾讯笔试挂归