如何显示当前系统时间并保存至纯文本文件里?

灼眼的超哥 2010-10-16 09:49:09
就是说,显示系统时间,例如:201010161000,就是一些数字,2010是年,10是月,16是日,10是小时,00是分钟。
显示后,将这些数字写入到文本文件里,没有这个文件就创建它并写入,有的话就不写入。
...全文
622 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
LonlyGod 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 lgch123456 的回复:]

引用 4 楼 rendao0563 的回复:

echo %date%%time% > time.txt
但是这个好像不行哦,
这样可以试试:date > time.txt
[/Quote]
这个真行
lgch123456 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rendao0563 的回复:]

echo %date%%time% > time.txt
[/Quote]但是这个好像不行哦,
这样可以试试:date > time.txt
lgch123456 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 void_wuyu 的回复:]

一句批处理就搞定了。
[/Quote]同意。。。
灼眼的超哥 2010-10-20
  • 打赏
  • 举报
回复
我只是自学,凭兴趣的。
meihao3601 2010-10-17
  • 打赏
  • 举报
回复
我们还没有学到文件操作...
swl82560397pq 2010-10-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lishanchao 的回复:]
C/C++ code

#include <stdio.h>
#include <time.h>

int main()
{
time_t s;
struct tm *p;
FILE *fp;
char *fname="timenow.txt";
s=time((time_t*)NULL);
p=gmtime(&s);……
[/Quote]

小魔菇 2010-10-16
  • 打赏
  • 举报
回复
3楼正解
rendao0563 2010-10-16
  • 打赏
  • 举报
回复
echo %date%%time% > time.txt
沭水河畔 2010-10-16
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <time.h>

int main()
{
time_t s;
struct tm *p;
FILE *fp;
char *fname="timenow.txt";
s=time((time_t*)NULL);
p=gmtime(&s);

fp=fopen(fname,"w+");
fprintf(fp,"%d-%d-%d %d:%d:%d\n",1900+p->tm_year,1+p->tm_mon, \
p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
fclose(fp);
printf("Year:%d\n",1900+p->tm_year);
printf("Month:%d\n",1+p->tm_mon);
printf("Day:%d\n",p->tm_mday);
printf("Hour:%d\n",p->tm_hour);
printf("Minute:%d\n",p->tm_min);
printf("Second:%d\n",p->tm_sec);
return 0;
}
沭水河畔 2010-10-16
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <time.h>

int main()
{
time_t s;
struct tm *p;
FILE *fp;
char *fname="timenow.txt";
s=time((time_t*)NULL);
p=gmtime(&s);

fp=fopen(fname,"w+");
fprintf(fp,"%d-%d-%d %d:%d:%d\n",1900+p->tm_year,1+p->tm_mon, \
p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
fclose(fp);
printf("Year:%d\n",1900+p->tm_year);
printf("Month:%d\n",1+p->tm_mon);
printf("Day:%d\n",p->tm_mday);
printf("Hour:%d\n",p->tm_hour);
printf("Minute:%d\n",p->tm_min);
printf("Second:%d\n",p->tm_sec);
return 0;
}
沭水河畔 2010-10-16
  • 打赏
  • 举报
回复
大体是这个样子:

#include <stdio.h>
#include <time.h>

int main()
{
time_t s;
struct tm *p;
FILE *fp;
char *fname="timenow.txt";
s=time((time_t*)NULL);
p=gmtime(&s);

fp=fopen(fname,"w+");
fprintf(fp,"%d-%d-%d %d:%d:%d\n",1900+p->tm_year,1+p->tm_mon, \
p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
fclose(fp);
printf("Year:%d\n",1900+p->tm_year);
printf("Month:%d\n",1+p->tm_mon);
printf("Day:%d\n",p->tm_mday);
printf("Hour:%d\n",p->tm_hour);
printf("Minute:%d\n",p->tm_min);
printf("Second:%d\n",p->tm_sec);
return 0;
}

Ubuntu 9.04+gcc编译通过。
ithiker 2010-10-16
  • 打赏
  • 举报
回复
学习学习...
manytao 2010-10-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lishanchao 的回复:]
C/C++ code

#include <stdio.h>
#include <time.h>

int main()
{
time_t s;
struct tm *p;
FILE *fp;
char *fname="timenow.txt";
s=time((time_t*)NULL);
p=gmtime(&s);……
[/Quote]

顶。
小魔菇 2010-10-16
  • 打赏
  • 举报
回复
为什么之有3楼和6楼?两位很危险啊?!
3楼回答的很OK了
乐CC 2010-10-16
  • 打赏
  • 举报
回复
一句批处理就搞定了。

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧