帮帮我吧!高手们

kenxsx 2007-06-20 11:36:30
我想做一个模拟银行取款的简单的程序,但是我想提取计算机的系统时间,请问用怎样的函数,怎样用法?请各位高手教教我.多谢!
...全文
316 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixivip1 2007-06-23
  • 打赏
  • 举报
回复
哦。。另外。。string time=__TIME__并不是说字符串变量string 里面的值就会跟随__TIME__而变化,在二次调用以前需要用再次对time进行赋值才可以。。也许你的问题应该是这样的
lixivip1 2007-06-23
  • 打赏
  • 举报
回复
为什么只有第一次讲行编译及运行所提取的时间是同计算机系统时间一致外,其它的提取的时间都同第一次提取的时间是一样.
因为你的计算机运行速度太快了。。。2次提取的时间差没有超过1秒,如果希望有时间差,可以用延时来实现,,,当然,,10000个if循环也可以
hell_wolf 2007-06-23
  • 打赏
  • 举报
回复
TIME__,__DATE__
是预处理时的时间,相当于编译时间,如果引用也是作为常数定死在程序中的.
achang84 2007-06-23
  • 打赏
  • 举报
回复
time_t start,end;
char szInput [256];
double dif;

time (&start);
printf ("Please, enter your name: ");
gets (szInput);
time (&end);
dif = difftime (end,start); // 时间差
Inhibitory 2007-06-23
  • 打赏
  • 举报
回复
查c的帮助文档,里面有很多关于时间的函数:把里面的函数都试一遍,就差不多能掌握简单的时间处理了.

cppreference.com -> 标准c时间与日期函数 -> 详解

标准c时间与日期函数

--------------------------------------------------------------------------------

asctime
语法:


#include <time.h>
char *asctime( const struct tm *ptr );


功能: 函数将ptr所指向的时间结构转换成下列字符串:

day month date hours:minutes:seconds year\n\0
例如:

Mon Jun 26 12:03:53 2000
相关主题:
localtime(), gmtime(), time(), and ctime().


--------------------------------------------------------------------------------

clock
语法:


#include <time.h>
clock_t clock( void );


功能:函数返回自程序开始运行的处理器时间,如果无可用信息,返回-1。 转换返回值以秒记, 返回值除以CLOCKS_PER_SECOND. (注: 如果编译器是POSIX兼容的, CLOCKS_PER_SECOND定义为1000000.)

相关主题:
time(), asctime(), and ctime().


--------------------------------------------------------------------------------

ctime
语法:


#include <time.h>
char *ctime( const time_t *time );


功能:函数转换参数time为本地时间格式:

day month date hours:minutes:seconds year\n\0
ctime() 等同

asctime( localtime( tp ) );
相关主题:
localtime(), gmtime(), time(), and asctime().


--------------------------------------------------------------------------------

difftime
语法:


#include <time.h>
double difftime( time_t time2, time_t time1 );


功能:函数返回时间参数time2和time1之差的秒数表示。

相关主题:
localtime(), gmtime(), time(), and asctime().


--------------------------------------------------------------------------------

gmtime
语法:


#include <time.h>
struct tm *gmtime( const time_t *time );


功能:函数返回给定的统一世界时间(通常是格林威治时间),如果系统不支持统一世界时间系统返回NULL。 警告!

相关主题:
localtime(), time(), and asctime().


--------------------------------------------------------------------------------

localtime
语法:


#include <time.h>
struct tm *localtime( const time_t *time );


功能:函数返回本地日历时间。警告!

相关主题:
gmtime(), time(), and asctime().


--------------------------------------------------------------------------------

mktime
语法:


#include <time.h>
time_t mktime( struct tm *time );


功能:函数转换参数time 类型的本地时间至日历时间,并返回结果。如果发生错误,返回-1。

相关主题:
time(), gmtime(), asctime(), and ctime().


--------------------------------------------------------------------------------

strftime
语法:


#include <time.h>
size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );


功能:函数按照参数fmt所设定格式将time类型的参数格式化为日期时间信息,然后存储在字符串str中(至多maxsize 个字符)。用于设定时间不同类型的代码为:

代码
含义

%a
星期的缩略形式

%A
星期的完整形式

%b
月份的缩略形式

%B
月份的完整形式

%c
月份的缩略形式

%d
月中的第几天(1-31)

%H
小时, 24小时格式 (0-23)

%I
小时, 12小时格式 (1-12)

%j
年中的第几天(1-366)

%m
月份 (1-12). Note: 某些版本的Microsoft Visual C++ 可能使用取值范围0-11.

%M
分钟(0-59)

%p
本地时间的上午或下午(AM or PM)

%S
秒钟(0-59)

%U
年中的第几周,星期天是一周的第一天

%w
星期几的数字表示(0-6, 星期天=0)

%W
一年中的第几周,星期天是一周的第一天

%x
标准日期字符串

%X
标准时间字符串

%y
年(0-99)

%Y
用CCYY表示的年(如:2004)

%Z
时区名

%%
百分号


函数strftime()返回值为处理结果字符串str中字符的个数,如果发生错误返回零。

相关主题:
time(), localtime(), and gmtime().


--------------------------------------------------------------------------------

time
语法:


#include <time.h>
time_t time( time_t *time );


功能: 函数返回当前时间,如果发生错误返回零。如果给定参数time ,那么当前时间存储到参数time中。

相关主题:
localtime(), gmtime(), strftime(), ctime(),
hokkien 2007-06-21
  • 打赏
  • 举报
回复
API
banzhiyu 2007-06-21
  • 打赏
  • 举报
回复
路过,学习
fengdream 2007-06-21
  • 打赏
  • 举报
回复
调用一下这个库函数 time_t time( time_t *timer );
这个函数返回自从1970年1月1日00.00.00时刻到现在走过的 tick数,连续两次调用这个函数的差值就是时间差了。。。
since midnight (00:00:00), January 1, 1970
kenxsx 2007-06-20
  • 打赏
  • 举报
回复
多谢
fan690265281 2007-06-20
  • 打赏
  • 举报
回复
知道了
lixivip1 2007-06-20
  • 打赏
  • 举报
回复
cout<<__TIME__,系统当前时间
cout<<__DATE__,系统当前日期
必须大写,而且下划线是2个不是一个
kenxsx 2007-06-20
  • 打赏
  • 举报
回复
为什么只有第一次讲行编译及运行所提取的时间是同计算机系统时间一致外,其它的提取的时间都同第一次提取的时间是一样.
lixivip1 2007-06-20
  • 打赏
  • 举报
回复
#include<iostream>
#include<string>
using namespace std;
int main()
{
string time=__TIME__;
int hou,minu,sec;
if(3==sscanf(time.c_str(),"%d:%d:%d",&hou,&minu,&sec))
cout<<hou<<" "<<minu<<" "<<sec<<endl;
getchar();
}
这样有没有给你点启发呢
kenxsx 2007-06-20
  • 打赏
  • 举报
回复
但是我分别提取两个不同的计算机系统时间,然后计算它们的差值?

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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