软件培训C,谁做过:“显示明天的日期的 ” 题目!指点下

flying751 2006-07-29 10:23:07
软件培训C,谁做过:“显示明天的日期的 ” 题目!指点下
...全文
200 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
y81348016 2006-07-29
  • 打赏
  • 举报
回复
定义data ,month, year;判断year是否为闰年 写个判断闰年的函数 显示明天的日期有3种情况: 普通在日期后面+1;如果为月末 则data=1;month+1; 如果是12月31日 则 year+1;month=1;data=1;有个代码:
#include "stdafx.h"
#include "stdio.h"

int main(int argc ,char *argv[])
{
struct date{

int month;
int day;
int year;
};
struct date today, tomorrow;
const int daysperMonth[12] = { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
printf ("Enter today's date (mm dd yyyy): ");
scanf ("%i%i%i", &today.month, &today.day, &today.year);
if(today.day != daysperMonth[today.month - 1 ] ){
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
else if ( today.month == 12){
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
else{
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
printf ("Tomorrow's date is %i/%i/%.2i.\n", tomorrow.month, tomorrow.day, tomorrow.year % 100);

return 0;
}
没考虑闰年的情况 楼主可以自己加进来
Heaven_Redsky 2006-07-29
  • 打赏
  • 举报
回复
实现起来技术难度不大
就是比较麻烦 主要是要考虑的东西比较多
如果是特定环境的话 还要考虑公元前纪年
不知道大家有没有比较成型的?
flying751 2006-07-29
  • 打赏
  • 举报
回复
谢谢二位!重点在当月份为最后一天,月份要变!一年的最后一天年要变!同时闰月!
Dong 2006-07-29
  • 打赏
  • 举报
回复
#include<time.h>
main()
{
time_t timep;
strcut tm *p;
time(&timep);
p=localtime(&timep);
p->mday += 1;
printf("%s\n",p);
}
//这样不知道怎样,改进有那么一点作用,你自己看看行不行!
飞哥 2006-07-29
  • 打赏
  • 举报
回复
明天日期是什么意思
struct tm LogServer::setNextTime(int internal)
{
struct tm when;
time_t now, result;
int days=internal;
time( &now );
when = *localtime( &now );
//printf( "Current time is %s\n", asctime( &when ) );
when.tm_mday = when.tm_mday + days;
if( (result = mktime( &when )) != (time_t)-1 )
{
//snprintf(ptime,36,asctime( &when ));
//printf( "In %d days the time will be %s\n", days, asctime( &when ) );
return when;
}
else
return NULL;
}

看我这个函数行不?
zez 2006-07-29
  • 打赏
  • 举报
回复
直接用系统函数..
什么都不用考虑..
写系统函数的考虑的比你周到的多!!!!!

70,037

社区成员

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

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