| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5957 人关注过本帖
标题:c语言怎么输出日期啊
只看楼主 加入收藏
cccer
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2004-5-5
收藏
 问题点数:0 回复次数:13 
c语言怎么输出日期啊
谢谢
搜索更多相关主题的帖子: c语言 输出 
2004-05-11 20:11
flytosky
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2004-5-10
收藏
得分:0 

main()

{

int year,moth,day;

year=2004;

moth=5;

day=11;

printf("The date is the %d,%d,%d",year,moth,day);

}


嘿嘿
2004-05-11 21:06
天使预备役
Rank: 2
等 级:论坛游民
威 望:3
帖 子:670
专家分:10
注 册:2004-4-6
收藏
得分:0 

在dos头文件中有一个time结构:

struct time { unsigned char ti_min; /* Minutes */ unsigned char ti_hour; /* Hours */ unsigned char ti_hund; /* Hundredths of seconds */ unsigned char ti_sec; /* Seconds */ };

在程序中就可以包含头文件dos,然后直接使用这个结构就可以,然后用gettime()获的时间!!!

函数名: gettime 功 能: 取得系统时间 用 法: void gettime(struct time *timep); 程序例:

#include <stdio.h> #include <dos.h>

int main(void) { struct time t;

gettime(&t); printf("The current time is: %2d:%02d:%02d.%02d\n", t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); return 0; }

函数名: settime 功 能: 设置系统时间 用 法: void settime(struct time *timep); 程序例:

#include <stdio.h> #include <dos.h>

int main(void) { struct time t;

gettime(&t); printf("The current minute is: %d\n", t.ti_min); printf("The current hour is: %d\n", t.ti_hour); printf("The current hundredth of a second is: %d\n", t.ti_hund); printf("The current second is: %d\n", t.ti_sec);

/* Add one to the minutes struct element and then call settime */ t.ti_min++; settime(&t);

return 0; }


差点把你忘了...
2004-05-12 09:36
mingyue
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2004-5-13
收藏
得分:0 

楼主是要输出日期,不是时间吧。

用void getdate(struct date *dateblk)函数取得系统日期


2004-05-13 17:19
天使预备役
Rank: 2
等 级:论坛游民
威 望:3
帖 子:670
专家分:10
注 册:2004-4-6
收藏
得分:0 

连这个错误你也提过分,我想是一样的!!!!

哈哈哈。。。。(不好意思!):(


差点把你忘了...
2004-05-14 09:54
jtf1985
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2004-7-29
收藏
得分:0 

例2不太高级

怎么设置的时间啊?

我没看出来


2004-08-01 10:51
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
settime(&amp;t);  这个函数

淘宝杜琨
2004-08-01 11:54
wonderfulday
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-7-28
收藏
得分:0 

在dos头文件中有一个time结构:

struct time { unsigned char ti_min; /* Minutes */ unsigned char ti_hour; /* Hours */ unsigned char ti_hund; /* Hundredths of seconds */ unsigned char ti_sec; /* Seconds */ };

在程序中就可以包含头文件dos,然后直接使用这个结构就可以,然后用gettime()获的时间!!!

函数名: gettime 功 能: 取得系统时间 用 法: void gettime(struct time *timep); 程序例:

.....................

请问有没有书是专门介绍这些头文件和相关函数用法的???

很想学!~


2004-08-01 20:50
jtf1985
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2004-7-29
收藏
得分:0 

我运行了

不能设置时间啊


2004-08-02 18:05
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 

那你一定是用WINDOWS系统了(众人:废话,就你还在用LINUX了。 神:5555),因为在WINDOWS系统的右下脚有个时钟程序,你的程序的优先级肯定没他高,所以啊,你设置完后肯定还会被他改回来。至于有些程序可以设置的,那我就不知道他调用什么了(也许是BIOS中断那!)~反正用settime我是从来没成功过。

stime可以帮你改变日期

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

main() { time_t t; t=time(NULL); printf("Now the time is %s",ctime(&t)); getch();

t-=24L*60L*60L; stime(&t);

printf("Now the time is %s",ctime(&t)); getch(); }

其中时间计算的格式是: 小时L*分钟L*秒L 所以 t-=24L*60L*60L; 的作用就是把你的日期提前一天!

关于C语言函数库的书籍。很多呀,不过好贵 55 块,都顶得我去网吧打30小时的魔兽了! 其中优秀的书籍有:《C函数实用手册》冶金工业出版社出版 作者:(不知道,我忘记了)。该书内介绍的函数都是按功能划分,介绍他在哪个头文件中,并且举例说明。内容大大地丰富! 我都不舍得买啊,要查都要跑5公里到图书馆去~ 谁买了一定要他开个讲座,每天讲1~2函数的用法才行!

其实网络上面也有类似的,不过他不是按照功能种类来划分函数的作用,他是按照开头字母顺序~郁闷!~要的话我打包给你都行

[此贴子已经被作者于2004-08-03 08:14:59编辑过]


淘宝杜琨
2004-08-03 08:08
快速回复:c语言怎么输出日期啊
数据加载中...
 
   



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

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