关于JULIAN DATE计算过去到现在的天数

satertt 2008-10-02 10:25:48
#include <iostream>
#include <cmath>
#include <time.h>

using namespace std;

long julian(int year, int month, int day)
{
long jy=year,jm=month,jd=day;
if (jy<0) jy=jy+1;
if (month>2)jm=jm+1;else jm=jm+13;jy=jy-1;
long jul=floor(365.25*jy)+floor(30.6001*jm)+jd+1720995.0;
if (jy<1582&&jm<10&&jd<15)return julian;
else int ja=0.01*jy;jul=jul+2-ja+0.25*ja; return julian;
}

int main()
{
struct tm *tm_now;
time_t time_now;
time_now=time(NULL);
tm_now=localtime(&time_now);
int jy,jm,jd;
cout<<"This is a Julian Day calculator,it can calculator how many days between the date you enter and today's date."<<endl
<<"Please enter the date you want to calculate:"<<endl<<"year = ";
cin>>jy;
cout<<endl<<"month = ";
cin>>jm;
cout<<endl<<"day = ";
cin>>jd;
int tm_day=tm_now->tm_mday, tm_month=tm_now->tm_mon+1,tm_yearl=tm_now->tm_year+1900;
long t=julian(int tm_yearl,int tm_month,int tm_day)- long julian (int jy,int jm,int jd);
cout <<"The julian Day between year:"<<jy<<" month:"<<jm<<" day:"<<jd<<"to year:"<<tm_yearl<<" month:"<<tm_month<<" day;"<<tm_day<<"is:"<<endl;
cout << t;
return 0;
}

本人写的的个软件,JULIAN的公式是老师给的,要计算某一天(JY-JM-JD)到现在的天数
涉及到系统时间提取,有点弄不清楚怎么处理,把系统报的错也写上来把,大家帮帮忙

------ Build started: Project: 4, Configuration: Debug Win32 ------
Compiling...
Haoyu Wu A3-1.cpp
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(12) : warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(13) : error C2440: 'return' : cannot convert from 'long (__cdecl *)(int,int,int)' to 'long'
There is no context in which this conversion is possible
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(14) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(14) : error C2065: 'ja' : undeclared identifier
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(14) : error C2065: 'ja' : undeclared identifier
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(14) : error C2440: 'return' : cannot convert from 'long (__cdecl *)(int,int,int)' to 'long'
There is no context in which this conversion is possible
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(32) : error C2144: syntax error : 'int' should be preceded by ')'
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(32) : error C2660: 'julian' : function does not take 0 arguments
c:\documents and settings\tao\桌面\4\4\haoyu wu a3-1.cpp(32) : error C2059: syntax error : ')'
Build log was saved at "file://c:\Documents and Settings\Tao\桌面\4\4\Debug\BuildLog.htm"
4 - 7 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
...全文
991 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gsmlovewxj 2010-06-24
  • 打赏
  • 举报
回复
回答的都很专业,呵呵呵呵
matrixdwy 2008-10-02
  • 打赏
  • 举报
回复
如果这种程序给老板看,LZ当场就要失业了。。。
zclever 2008-10-02
  • 打赏
  • 举报
回复

//看不懂你们老师的算法。。。汗。
//参照以前有个帖子写的。计算输入日期和当前日期之间的天数
#include <time.h>
#include <iostream>
using namespace std;

int main()
{
struct tm *input_date=new struct tm;
struct tm *current_date,*now_date;
memset(now_date,0,sizeof(struct tm));
memset(input_date,0,sizeof(struct tm));
int year,mon,day;
time_t current_time;
current_time=time(NULL);
current_date=localtime(¤t_time);
now_date->tm_year=current_date->tm_year;
now_date->tm_mon=current_date->tm_mon;
now_date->tm_mday=current_date->tm_mday;
cout<<"Current date is: "<<now_date->tm_year+1900<<"-"<<now_date->tm_mon+1<<"-"<<now_date->tm_mday;
cout<<endl;


cout<<"Please input your date! "<<endl;
cin>>year>>mon>>day;
input_date->tm_year=year-1900;
input_date->tm_mon=mon-1;
input_date->tm_mday=day;


double sub=0.0;
sub=difftime(mktime(now_date),mktime(input_date));
sub/=60*60*24;

cout<<"The sub days between are: ";
cout<<sub<<endl;

return 0;
}

/*试验数据:
Current date is: 2008-10-2
Please input your date!
2007 9 20
The sub days between are: 378


Terminated with return code 0
Press any key to continue ...

*/

HengStar 2008-10-02
  • 打赏
  • 举报
回复
什么乱七八糟的...风格也乱的一塌糊涂了-.-
return julian; 是什么?julian是函数名,怎么能作为返回值呢?

else int ja=0.01*jy;jul=jul+2-ja+0.25*ja; return julian; // else后面不加大括号的话它只会对一条语句起作用,也就是int ja=0.01*jy;这句
但是你是在else的作用域里面定义的ja,而表达式jul=jul+2-ja+0.25*ja;是在else语句外面的,所以无法使用ja变量,应该像这样
else
{
int ja=0.01*jy;
jul=jul+2-ja+0.25*ja;
}
下面这句就更不可思议了,
long t=julian(int tm_yearl,int tm_month,int tm_day)- long julian (int jy,int jm,int jd);
函数的调用实参里面怎么能定义变量呢,而且你这些变量在前面都定义过了,重复定义了,
long julian (int jy,int jm,int jd);
上面这句明明就是函数声明的形式,怎么作为表达式使用了呢
正确的用法至少应该像这样
long t=julian(tm_yearl,tm_month,tm_day)- julian(jy,jm,jd);

下面是修正后可以通过编译的完整程序,但我不保证结果一定正确,我也没去仔细看你的实际想实现的功能,建议把基本的东西先弄明白了再着手写程序吧

#include <iostream>
#include <cmath>
#include <time.h>

using namespace std;

long julian(int year, int month, int day)
{
long jy=year,jm=month,jd=day;
if (jy <0) jy=jy+1;
if (month>2)jm=jm+1;else jm=jm+13;jy=jy-1;
long jul=floor(365.25*jy)+floor(30.6001*jm)+jd+1720995.0;
if (jy <1582&&jm <10&&jd <15)
{
return jul;
}
else
{
int ja=0.01*jy;jul=jul+2-ja+0.25*ja;
return ja;
}
}

int main()
{
struct tm *tm_now;
time_t time_now;
time_now=time(NULL);
tm_now=localtime(&time_now);
int jy,jm,jd;
cout <<"This is a Julian Day calculator,it can calculator how many days between the date you enter and today's date." <<endl
<<"Please enter the date you want to calculate:" <<endl <<"year = ";
cin>>jy;
cout <<endl <<"month = ";
cin>>jm;
cout <<endl <<"day = ";
cin>>jd;
int tm_day=tm_now->tm_mday, tm_month=tm_now->tm_mon+1,tm_yearl=tm_now->tm_year+1900;
long t=julian(tm_yearl,tm_month,tm_day)- julian (jy,jm,jd);
cout <<"The julian Day between year:" <<jy <<" month:" <<jm <<" day:" <<jd <<"to year:" <<tm_yearl <<" month:" <<tm_month <<" day;" <<tm_day <<"is:" <<endl;
cout << t;
return 0;
}

wuyu637 2008-10-02
  • 打赏
  • 举报
回复
基础很差,好好看书。先写短的程序开始。
wuyu637 2008-10-02
  • 打赏
  • 举报
回复
// acm.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include < iostream>
#include <vector>
using namespace std;

#include <iostream>


#include <vector>

#include <stdio.h>

#include <string>
using namespace std;
#include<iostream>
#include<string>
#include<vector>
#include <ctime>

#include <iostream>
#include <cstdlib>
using namespace std;
#include <stdio.h>
#define SIZE 3
#include <iostream>
using namespace std;

#include <iostream>
using namespace std;
#define N 10

#include "ICTCLAS30.h"
#define IDS_APP_TITLE 103

// 新对象的下一些默认值
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif


#include <fstream>
using namespace std;
#include <iostream>
#include <cmath>
#include <time.h>

using namespace std;

long julian(int year, int month, int day)
{
int ja;
long jy=year,jm=month,jd=day;
if (jy <0) jy=jy+1;
if (month>2)jm=jm+1;else jm=jm+13;jy=jy-1;
long jul= floor(365.25*jy)+floor(30.6001*jm)+jd+1720995.0;
if (jy<1582 && jm<10 && jd<15)
//julian是个函数,不能这么用
//return julian;
return 0;
else ja=0.01*jy;jul=jul+2-ja+0.25*ja;
//return julian; julian是个函数名。
return 0;
}

int main()
{
struct tm *tm_now;
time_t time_now;
time_now=time(NULL);
tm_now=localtime(&time_now);
int jy,jm,jd;
cout <<"This is a Julian Day calculator,it can calculator how many days between the date you enter and today's date." <<endl
<<"Please enter the date you want to calculate:" <<endl <<"year = ";
cin>>jy;
cout <<endl <<"month = ";
cin>>jm;
cout <<endl <<"day = ";
cin>>jd;
int tm_day=tm_now->tm_mday, tm_month=tm_now->tm_mon+1,tm_yearl=tm_now->tm_year+1900;

long t;
//这个是什么啊?函数调用要传入实参。
//t=julian(int tm_yearl,int tm_month,int tm_day)- long julian (int jy,int jm,int jd);

cout <<"The julian Day between year:" <<jy <<" month:" <<jm <<" day:" <<jd <<"to year:" <<tm_yearl <<" month:" <<tm_month <<" day;" <<tm_day <<"is:" <<endl;
cout << t;
return 0;
}

64,645

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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