c语言获取系统时间 程序实现
2014-04-20 09:35
375 查看
1、
#include"stdafx.h"
#include<stdio.h>
#include<time.h>
#include<Windows.h>
int main(void)
{
time_t timer=time(NULL);
printf("ctime is%s\n",ctime(&timer));//得到日历时间
system("pause");
return 0;
}
输出为:
ctime isSun Apr 20 09:07:27 2014
请按任意键继续. . .
2、
#include"stdafx.h"
#include<time.h>
#include<stdio.h>
#include<dos.h>
#include<Windows.h>
int main()
{
time_t timer;
struct tm*tblock;
timer=time(NULL);
tblock=localtime(&timer);
printf("Localtimeis:%s",asctime(tblock));
system("pause");
return 0;
}
输出为:
Localtimeis:Sun Apr 20 09:10:00 2014
请按任意键继续. . .
3、
#include"stdafx.h"
#include<Windows.h>
#include<stdio.h>
#include<time.h>
int main()
{
time_t t;
time(&t);
printf("Today's date and time:%s",ctime(&t));
system("pause");
return 0;
}
输出为:
Today's date and time:Sun Apr 20 09:13:23 2014
请按任意键继续. . .
4、
#include"stdafx.h"
#include<Windows.h>
#include<time.h>
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
time_t first,second;
//system("cls");//clrscr()是TC里的
first=time(NULL);
Sleep(2000);//延迟函数,delay()是TC的
second=time(NULL);
printf("The difference is:%f seconds",difftime(second,first));//得到两次机器时间差,单位为秒
system("pause");
return 0;
}
输出为:
The difference is:2.000000 seconds请按任意键继续. . .
5、
#include"stdafx.h"
#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
#include"stdafx.h"
#include<Windows.h>
char*tzstr="TZ=PST8PDT";//数字来改变时区,8代表
int main()
{
time_t t;
struct tm*gmt,*area;
putenv(tzstr);//把字符串加到当前环境中
tzset();//UNIX兼容函数,用于得到时区,在DOS环境下无用途
t=time(NULL);
area=localtime(&t);
printf("Localtime is:%s",asctime(area));
gmt=gmtime(&t);//得到以结构tm表示的时间信息
printf("GMT is:%s",asctime(gmt));
system("pause");
return 0;
}
输出为:
Localtime is:Sat Apr 19 18:34:40 2014
GMT is:Sun Apr 20 01:34:40 2014
请按任意键继续. . .
http://baike.baidu.com/view/1741851.htm
1、
#include"stdafx.h"
#include<stdio.h>
#include<time.h>
#include<Windows.h>
int main(void)
{
time_t timer=time(NULL);
printf("ctime is%s\n",ctime(&timer));//得到日历时间
system("pause");
return 0;
}
输出为:
ctime isSun Apr 20 09:07:27 2014
请按任意键继续. . .
2、
#include"stdafx.h"
#include<time.h>
#include<stdio.h>
#include<dos.h>
#include<Windows.h>
int main()
{
time_t timer;
struct tm*tblock;
timer=time(NULL);
tblock=localtime(&timer);
printf("Localtimeis:%s",asctime(tblock));
system("pause");
return 0;
}
输出为:
Localtimeis:Sun Apr 20 09:10:00 2014
请按任意键继续. . .
3、
#include"stdafx.h"
#include<Windows.h>
#include<stdio.h>
#include<time.h>
int main()
{
time_t t;
time(&t);
printf("Today's date and time:%s",ctime(&t));
system("pause");
return 0;
}
输出为:
Today's date and time:Sun Apr 20 09:13:23 2014
请按任意键继续. . .
4、
#include"stdafx.h"
#include<Windows.h>
#include<time.h>
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
time_t first,second;
//system("cls");//clrscr()是TC里的
first=time(NULL);
Sleep(2000);//延迟函数,delay()是TC的
second=time(NULL);
printf("The difference is:%f seconds",difftime(second,first));//得到两次机器时间差,单位为秒
system("pause");
return 0;
}
输出为:
The difference is:2.000000 seconds请按任意键继续. . .
5、
#include"stdafx.h"
#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
#include"stdafx.h"
#include<Windows.h>
char*tzstr="TZ=PST8PDT";//数字来改变时区,8代表
int main()
{
time_t t;
struct tm*gmt,*area;
putenv(tzstr);//把字符串加到当前环境中
tzset();//UNIX兼容函数,用于得到时区,在DOS环境下无用途
t=time(NULL);
area=localtime(&t);
printf("Localtime is:%s",asctime(area));
gmt=gmtime(&t);//得到以结构tm表示的时间信息
printf("GMT is:%s",asctime(gmt));
system("pause");
return 0;
}
输出为:
Localtime is:Sat Apr 19 18:34:40 2014
GMT is:Sun Apr 20 01:34:40 2014
请按任意键继续. . .
http://baike.baidu.com/view/1741851.htm
相关文章推荐
- C语言实现获取系统时间,转换成时分秒年月日 (vs2015亲测可用)
- C语言实战应用第一课:获取系统当前时间
- VC获取系统时间、程序运行时间
- vc 程序效率测试 与 如何获取系统精确时间
- 程序中系统时间的获取
- c语言获取系统当前时间
- Cocos2d-x中用C++获取当前系统时间,实现跨平台
- c语言获取系统时间的几种方式
- C语言获取微秒级的系统时间 gettimeofday timeval timeout
- C语言获取系统时间
- 32位程序在64位系统上获取系统安装时间(要使用KEY_WOW64_64KEY标记)
- VC获取系统时间、程序运行时间
- C语言获取系统时间
- Linux下获得系统时间的C语言的实现方法
- C语言获取系统当前时间
- jQuery动态地获取系统时间实现代码
- c语言实现获取macos当前的系统语言
- C语言获取系统时间的几种方式
- Linux下获得系统时间的C语言的实现方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法