急!关于时间的问题

zscedu 2011-07-04 10:17:49
知道一个时间(年月日时分秒),想在这个时间上加上一个秒数,比如加3、5、16...秒,怎么得得到计算后的时间(年月日时分秒)?? 能不能用c语言实现?
...全文
167 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
zscedu 2011-07-08
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 dxwsdosdo 的回复:]
#include <time.h> 这个头文件里边有函数 ,楼主自己找。
[/Quote]
谢谢了
zscedu 2011-07-05
  • 打赏
  • 举报
回复
要把秒转换成日期型的,难道只能自己写函数实现了?大家帮帮忙吧!!!
dxwsdosdo 2011-07-05
  • 打赏
  • 举报
回复
#include <time.h> 这个头文件里边有函数 ,楼主自己找。
赵4老师 2011-07-04
  • 打赏
  • 举报
回复
仅供参考
#include <afxdisp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, TCHAR* argv[]) {
COleDateTime t;
COleDateTimeSpan ts;
CString s,fmt;
int nYear;
int nMonth;
int nDay;
int nHour;
int nMin;
int nSec;
int lDays;
int nHours;
int nMins;
int nSecs;
int i,N;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
printf("Fatal Error: MFC initialization failed\n");
return 1;
}
if (argc<13) {
printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
return 2;
}
if (stricmp(argv[12],"SQL")==0) fmt="%Y-%m-%d %H:%M:%S";
else if (stricmp(argv[12],"YYYY")==0) fmt="%Y%m%d %H%M%S";
else if (stricmp(argv[12],"YY")==0) fmt="%y%m%d %H%M%S";
else {
printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
return 3;
}
nYear =atoi(argv[ 1]);
nMonth=atoi(argv[ 2]);
nDay =atoi(argv[ 3]);
nHour =atoi(argv[ 4]);
nMin =atoi(argv[ 5]);
nSec =atoi(argv[ 6]);
lDays =atoi(argv[ 7]);
nHours=atoi(argv[ 8]);
nMins =atoi(argv[ 9]);
nSecs =atoi(argv[10]);
N =atoi(argv[11]);
if (N<=0) {
printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
return 4;
}
t=COleDateTime( nYear, nMonth, nDay, nHour, nMin, nSec);
ts=COleDateTimeSpan( lDays, nHours, nMins, nSecs );
for (i=1;i<=N;i++) {
s=t.Format(fmt);
printf("%08d %s\n",i,s);
t=t+ts;
}
return 0;
}

The COleDateTime class handles dates from 1 January 100 – 31 December 9999.

zscedu 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luciferisnotsatan 的回复:]
ctime
[/Quote]
ctime 他是把时间转换成了字符串形式的,那再怎么办呀?请指教
至善者善之敌 2011-07-04
  • 打赏
  • 举报
回复
MFC 中用定时器timer很简单就可以实现

luciferisnotsatan 2011-07-04
  • 打赏
  • 举报
回复
ctime
zscedu 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 dizuo 的回复:]
C/C++ code


#include <time.h>
#include <string.h>
void test1()
{
tm start,end;
start.tm_year = 2011-1900; //年必须这么写
start.tm_mon = 6;
start.tm_mday = 20……
[/Quote]老兄,好像是把日期型的时间转换成了秒,那怎么把秒转换成日期型的呀?再给说说吧!谢谢!
  • 打赏
  • 举报
回复
自己写个函数计算也行。。。也不是多么复杂
qq120848369 2011-07-04
  • 打赏
  • 举报
回复
ctime,mktime,gettimeofday.
赵4老师 2011-07-04
  • 打赏
  • 举报
回复
不想用MFC的话直接对time_t类型的变量加减即可,因为
The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock.
ryfdizuo 2011-07-04
  • 打赏
  • 举报
回复

#include <time.h>
#include <string.h>
void test1()
{
tm start,end;
start.tm_year = 2011-1900; //年必须这么写
start.tm_mon = 6;
start.tm_mday = 20;
start.tm_hour = 20;
start.tm_min = 46;
start.tm_sec = 45;
//start.tm_isdst = 0;
end.tm_year = 2011-1900;
end.tm_mon = 6;
end.tm_mday = 20;
end.tm_hour = 20;
end.tm_min = 45;
end.tm_sec = 50;
//end.tm_isdst = 0;
double dif;
//dif = difftime ( mktime(&end), mktime(&start) );
time_t sta = mktime(&start);
time_t ed = mktime(&end);
dif = ed - sta;
//dif = difftime ( mktime(&end), mktime(&start) );
printf ("%.5lf minutes./n", dif / 60 );
time_t new_end = ed + 3*60; //3 minutes
tm* new1 = localtime(&new_end); //gmtime 是把time_t转化为国际标准时间
// printf("sizeof tm = %d/n", sizeof(tm)); // 36
}
赵4老师 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zscedu 的回复:]
引用 4 楼 zhao4zhong1 的回复:
仅供参考

C/C++ code

#include <afxdisp.h>
似乎无法识别,编译时报错
[/Quote]
VC6 IDE工程、设置、General、Microsoft Fundation Classes:选Use MFC in a Shared DLL
zscedu 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 q191201771 的回复:]
知道一个时间(年月日时分秒),想在这个时间上加上一个秒数,比如加3、5、16...秒,怎么得得到计算后的时间(年月日时分秒)?? 能不能用c语言实现?

你知道的是什么形式的呢? 字符串?
[/Quote]我知道的时间是字符串形式的
zscedu 2011-07-04
  • 打赏
  • 举报
回复
知道一个时间(年月日时分秒),想在这个时间上加上一个秒数,比如加3、5、16...秒,怎么得得到计算后的时间(年月日时分秒)?? 怎么用linux c实现呀?请大侠指点!!!
就想叫yoko 2011-07-04
  • 打赏
  • 举报
回复
知道一个时间(年月日时分秒),想在这个时间上加上一个秒数,比如加3、5、16...秒,怎么得得到计算后的时间(年月日时分秒)?? 能不能用c语言实现?

你知道的是什么形式的呢? 字符串?
  • 打赏
  • 举报
回复
来学习的
zscedu 2011-07-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhao4zhong1 的回复:]
仅供参考

C/C++ code

#include <afxdisp.h>
[/Quote]似乎无法识别,编译时报错

69,371

社区成员

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

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