可以教一下吗~~~~

qq_42674780 2018-07-12 10:15:41
我再CSDN上,找了一个 随即生成时间的代码,但是我不知道怎么使用,可以教一下吗。,, 谢谢
...全文
316 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
linfengc 2018-10-23
  • 打赏
  • 举报
回复
随机生成一个整数,就可以随机生成时间 time_t tTime; time(&tTime); struct tm tmTime; localtime_s(&tmTime, &tTime);
shen_wei 2018-09-25
  • 打赏
  • 举报
回复
楼主,贴出来你的代码,我们才能教你如何去做。。。
zhao_miao 2018-07-24
  • 打赏
  • 举报
回复
赵4老师 2018-07-12
  • 打赏
  • 举报
回复
仅供参考:
#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;
}

15,440

社区成员

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

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