| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 589 人关注过本帖
标题:[求助]时间函数
只看楼主 加入收藏
cutboy
Rank: 1
等 级:新手上路
帖 子:120
专家分:0
注 册:2007-9-16
收藏
 问题点数:0 回复次数:7 
[求助]时间函数

最近被时间函数搞的头昏脑胀,下面是一句话的程序:

asctime()函数是通过tm结构来生成具有固定格式的保存时间信息的字符串,而ctime()是通过日历时间来生成时间字符串。这样的话,asctime()函数只是把tm结构对象中的各个域填到时间字符串的相应位置就行了,而ctime()函数需要先参照本地的时间设置,把日历时间转化为本地时间,然后再生成格式化后的字符串。在下面,如果lt是一个非空的time_t变量的话,那么:

printf(ctime(<));

等价于:

struct tm *ptr;
ptr=localtime(<);
printf(asctime(ptr));


请问ptr=localtime(<);里的(<)是什么意思??????

搜索更多相关主题的帖子: 函数 时间 
2007-10-02 19:52
cince
Rank: 1
等 级:新手上路
威 望:1
帖 子:108
专家分:0
注 册:2007-1-21
收藏
得分:0 
{
....
L_T=time(NULL);
ptr=localtime(<);//Look at here
if(ptr->Tm_Min<59)
printf(tmpp,"echo%slat %.2d%.2d%.2d",cmd,ptr->Tm_Hour,ptr->Tm_Min,ptr->Tm_Sec);
else
if (ptr->Tm_Hour <23)
printf(tmpp,"echo %s | at %.2d0000",cmd,ptr->Tm_Hour+1);
else
printf(tmpp,"echo %s | at 000000",cmd);
system("tmpp");
}

[此贴子已经被作者于2007-10-3 10:22:56编辑过]


There Is Nothing Impossible In My Dictionary.
2007-10-03 10:20
cutboy
Rank: 1
等 级:新手上路
帖 子:120
专家分:0
注 册:2007-9-16
收藏
得分:0 
看不懂啊

2007-10-03 18:21
cutboy
Rank: 1
等 级:新手上路
帖 子:120
专家分:0
注 册:2007-9-16
收藏
得分:0 
斑主能不能说的详细点呢?

2007-10-03 20:58
shanying123
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-10-3
收藏
得分:0 

有关时间的函数有:
time(NULL),返回距离1970年1月1日到现在的秒数(返回值是long型);

localtime(time_t *);把日期和时间转变为结构(返回值是struct tm *)
gmtime(time_t *);
ctime(time_t *);把日期和时间转变为字符串(返回值是char *)//这三个函数的形参是一样的

asctime(struct tm *);把日期和时间转变为ASCII码(和ctime功能有相似之处,不过,形参是不同的);

综上所述,我觉得那个你那个函数应该是这样的:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{ time_t timer;
struct tm *ptr;
timer=time(NULL);

ptr=localtime(&timer);
printf("The current time is %s\n",asctime(ptr));
}

个人观点,如果曲解了楼主的意思,请见谅啊!

2007-10-04 00:41
浅色的回忆
Rank: 1
等 级:新手上路
帖 子:139
专家分:0
注 册:2007-6-24
收藏
得分:0 
以下是引用cutboy在2007-10-3 20:58:42的发言:
斑主能不能说的详细点呢?

上边我怎么看不见斑主?
where?


2007-10-04 02:34
zhy20045923
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-10-3
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
time_t timer;
struct tm *ptr;
timer=time(NULL);
ptr=localtime(&timer);
printf("The current time is %s\n",asctime(ptr));
}

输出结果是:
The current time is Tue Oct 04 08:47:04 2005

是不是错了,我的运行时间是星期四,2007年,其他没错

2007-10-04 08:48
xhf870404
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-10-4
收藏
得分:0 
我还是个新手,看不懂啊,有点可惜
2007-10-10 23:56
快速回复:[求助]时间函数
数据加载中...
 
   



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

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