| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1823 人关注过本帖
标题:求助:在C++中怎样获取系统时间?
只看楼主 加入收藏
qiyu3595
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-16
收藏
 问题点数:0 回复次数:10 
求助:在C++中怎样获取系统时间?
在C++中怎样获取系统时间?
搜索更多相关主题的帖子: 系统 获取 时间 
2006-05-16 06:37
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
可以去看看书,有专门介绍ctime的

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-05-16 20:14
loveb
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-8-23
收藏
得分:0 

知道的举个例子呀!谢谢了!~


2006-06-30 17:43
ligt0610
Rank: 1
等 级:新手上路
帖 子:204
专家分:5
注 册:2006-6-29
收藏
得分:0 
同问 也想知道

通过不断的学习与思考才是提高自己能力的最好途径。。。。。。。
2006-07-01 14:04
ysol
Rank: 1
等 级:新手上路
帖 子:107
专家分:0
注 册:2006-6-11
收藏
得分:0 

time.h
Standard C library with time and date related functions

Functions:
asctime Convert tm structure to string
clock Return number of clock ticks since process start
ctime Convert time_t value to string
difftime Return difference between two times
gmtime Convert time_t value to tm structure as UTC time
localtime Convert time_t value to tm structure as local time
mktime Convert tm structure to time_t value
time Get current time

time_t time ( time_t * timer );
Get current time.
Get the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC from the system clock.

Parameters.

timer
Location where to store the retrieved value. If this is NULL the value is not stored. But it is still returned by the function.
time_t is generally defined by default to long.
Return Value.
Elapsed time in seconds, as described.

Portability.
Defined in ANSI-C.


Example.


/* time example */
#include <stdio.h>
#include <time.h>

int main ()
{
time_t seconds;

seconds = time (NULL);
printf ("%ld hours since January 1, 1970", seconds/3600);

return 0;
}

Output:
266344 hours since January 1, 1970

2006-07-01 15:18
ysol
Rank: 1
等 级:新手上路
帖 子:107
专家分:0
注 册:2006-6-11
收藏
得分:0 

/* ctime example */
#include <stdio.h>
#include <time.h>

int main ()
{
time_t rawtime;

time ( &rawtime );
printf ( "Current date and time are: %s", ctime (&rawtime) );

return 0;
}

2006-07-01 15:22
chengenius
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-5-23
收藏
得分:0 
ctime?
和string类一样的吗?
2006-07-01 19:19
aogun
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:638
专家分:0
注 册:2006-4-5
收藏
得分:0 
以下是引用chengenius在2006-7-1 19:19:37的发言:
ctime?
和string类一样的吗?


ysol用的ctime只是一个将time_t类型的时间变量转成时间字符串,并不是类
如果想获取各种时间信息如年、月、日等,那么可以用localtime函数将time_t类型转成tm结构,tm结构中有详细的时间信息


世界上总共有 10 种人,一种懂得什么是二进制 ,一种不懂。
2006-07-03 09:16
向你们学习编程
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-7-3
收藏
得分:0 
不知道啊

2006-07-03 19:01
ot1122
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-20
收藏
得分:0 
time 
2006-07-08 10:51
快速回复:求助:在C++中怎样获取系统时间?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012641 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved