最近被时间函数搞的头昏脑胀,下面是一句话的程序:
asctime()函数是通过tm结构来生成具有固定格式的保存时间信息的字符串,而ctime()是通过日历时间来生成时间字符串。这样的话,asctime()函数只是把tm结构对象中的各个域填到时间字符串的相应位置就行了,而ctime()函数需要先参照本地的时间设置,把日历时间转化为本地时间,然后再生成格式化后的字符串。在下面,如果lt是一个非空的time_t变量的话,那么:
printf(ctime(<));
等价于:
struct tm *ptr;
ptr=localtime(<);
printf(asctime(ptr));
请问ptr=localtime(<);里的(<)是什么意思??????
----------------解决方案--------------------------------------------------------
{
....
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编辑过]
----------------解决方案--------------------------------------------------------
看不懂啊
----------------解决方案--------------------------------------------------------
斑主能不能说的详细点呢?
----------------解决方案--------------------------------------------------------
有关时间的函数有:
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));
}
个人观点,如果曲解了楼主的意思,请见谅啊!
----------------解决方案--------------------------------------------------------
斑主能不能说的详细点呢?
上边我怎么看不见斑主?
where?
----------------解决方案--------------------------------------------------------
#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年,其他没错
----------------解决方案--------------------------------------------------------
我还是个新手,看不懂啊,有点可惜
----------------解决方案--------------------------------------------------------