zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Java获取当地的日出日落时间代码分享

JAVA代码 获取 时间 分享 当地
2023-06-13 09:15:28 时间

根据经纬度和当前日期获取当地的日出日落时间,强大的Google搜索让我迅速找到了一个外国人写的一个java类,代码中的注释写得很清楚。
这里直接贴出代码来:

复制代码代码如下:

/******************************************************************************
*
*       SunriseSunset.java
*
*******************************************************************************
*
*JavaClass:SunriseSunset
*
* ThisJavaclassispartofacollectionofclassesdevelopedforthe
* readingandprocessingofoceanographicandmeterologicaldatacollected
* since1970byenvironmentalbuoysandstations. Thisdatasetis
* maintainedbytheNationalOceanographicDataCenterandispublicly
* available. TheseJavaclasseswerewrittenfortheUSEnvironmental
* ProtectionAgency"sNationalExposureResearchLaboratoryunderContract
* No.GS-10F-0073KwithNeptuneandCompanyofLosAlamos,NewMexico.
*
*Purpose:
*
* ThisJavaclassperformscalculationstodeterminethetimeof
* sunriseandsunsetgivenlat,long,anddate.
*
*Inputs:
*
* Latitude,longitude,date/time,andtimezone.
*
*Outputs:
*
* Localtimeofsunriseandsunsetascalculatedbythe
*  program.
* Ifnosunriseornosunsetoccurs,orifthesunisupallday
*  ordownallday,appropriatebooleanvaluesareset.
* Abooleanisprovidedtoidentifyifthetimeprovidedisduringtheday.
*
* Theabovevaluesareaccessedbythefollowingmethods:
*
*  Date getSunrise() returnsdate/timeofsunrise
*  Date getSunset()  returnsdate/timeofsunset
*  boolean isSunrise()  returnstrueiftherewasasunrise,elsefalse
*  boolean isSunset()  returnstrueiftherewasasunset,elsefalse
*  boolean isSunUp()  returnstrueifsunisupallday,elsefalse
*  boolean isSunDown()  returnstrueifsunisdownallday,elsefalse
*  boolean isDaytime()  returnstrueifsunisupatthetime
*         specified,elsefalse
*
*RequiredclassesfromtheJavalibrary:
*
* java.util.Date
* java.text.SimpleDateFormat
* java.text.ParseException;
* java.math.BigDecimal;
*
*Packageofwhichthisclassisamember:
*
* default
*
*Knownlimitations:
*
* Itisassumedthatthedataprovidedarewithinvalieranges
* (i.e.latitudebetween-90and+90,longitudebetween0and360,
* avaliddate,andtimezonebetween-14and+14.
*
*Compatibility:
*
* Java1.1.8
*
*References:

* Themathematicalalgorithmsusedinthisprogramarepatterned
* afterthosedebvelopedbyRogerSinnottinhisBASICprogram,
* SUNUP.BAS,publishedinSky&Telescopemagazine:
* Sinnott,RogerW."SunriseandSunset:AChallenge"
* Sky&Telescope,August,1994p.84-85
*
* Thefollowingisacross-indexofvariablesusedinSUNUP.BAS.
* Asingledefinitionfrommultiplereuseofvariablenamesin
* SUNUP.BASwasclarifiedwithvariousdefinitionsinthisprogram.
*
* SUNUP.BAS thisclass
*
* A   dfA
* A(2)  dfAA1,dfAA2
* A0   dfA0
* A2   dfA2
* A5   dfA5
* AZ   Notused
* C   dfCosLat
* C0   dfC0
* D   iDay
* D(2)  dfDD1,dfDD2
* D0   dfD0
* D1   dfD1
* D2   dfD2
* D5   dfD5
* D7   Notused
* DA   dfDA
* DD   dfDD
* G   bGregorian,dfGG
* H   dfTimeZone
* H0   dfH0
* H1   dfH1
* H2   dfH2
* H3   dfHourRise,dfHourSet
* H7   Notused
* J   dfJ
* J3   dfJ3
* K1   dfK1
* L   dfLL
* L0   dfL0
* L2   dfL2
* L5   dfLon
* M   iMonth
* M3   dfMinRise,dfMinSet
* N7   Notused
* P   dfP
* S   iSign,dfSinLat,dfSS
* T   dfT
* T0   dfT0
* T3   notused
* TT   dfTT
* U   dfUU
* V   dfVV
* V0   dfV0
* V1   dfV1
* V2   dfV2
* W   dfWW
* Y   iYear
* Z   dfZenith
* Z0   dfTimeZone


*Author/Company:
*
* JDT:JohnTauxe,NeptuneandCompany
* JMG:JoMarieGreen
*
*Changelog:

* date      ver   by descriptionofchange
* _________ _____ ___ ______________________________________________
* 5Jan01 0.006 JDT Excisedfromssapp.javav.0.005.
* 11Jan01 0.007 JDT Minormodificationstocommentsbasedon
*        materialfromSinnott,1994.
* 7Feb01 0.008 JDT Fixedbackwardstimezone. Thestandardisthat
*        localtimezoneisspecifiedinhoursEASTof
*        Greenwich,sothatESTwouldbe-5,forexample.
*        Forsomereason,SUNUP.BASdoesthisbackwards
*        (probablyanamericocentricperspective)and
*        SunriseSunsetadoptedthatconvention. Oops.
*        Sothesigninthemathischanged.
* 7Feb01 0.009 JDT Well,thatthrewofftheazimuthcalculation...
*        Removedtheazimuthcalculations.
* 14Feb01 0.010 JDT Addedabilitytoacceptatime(HH:mm)in
*        dateInput,anddecideifthattimeisdaytime
*        ornighttime.
* 27Feb01 0.011 JDT Addedaccessormethodsinplaceofhavingpublic
*        variablestogetresults.
* 28Feb01 0.012 JDT Cleaneduplistofimportedclasses.
* 28Mar01 1.10  JDT Finalversionaccompanyingdeliverable1b.
*   4Apr01 1.11  JDT Movedlogicsupporting.isDaytimeintomethod.
*        Movedcalculationsoutofconstructor.
*  01May01 1.12  JMG  Added"GMT"designationandtestinglines.
*  16May01 1.13  JDT  AddedsetLenient(false)andsetTimeZone(tz)
*                          todfmtDay,dfmtMonth,anddfmtYearin
*       doCalculations.
*  27Jun01 1.14  JDT RemovedrelianceonStationConstants(GMT).
* 13Aug01 1.20  JDT Finalversionaccompanyingdeliverable1c.
* 6Sep01 1.21  JDT Thoroughcodeandcommentreview.
* 21Sep01 1.30  JDT Finalversionaccompanyingdeliverable2.
* 17Dec01 1.40  JDT Versionaccompanyingfinaldeliverable.
*    
*----------------------------------------------------------------------------*/

//Importrequiredclassesandpackages
importjava.util.Date;
importjava.text.SimpleDateFormat;
importjava.text.ParseException;
importjava.math.BigDecimal;
importjava.util.TimeZone;


/******************************************************************************
* class:     SunriseSunsetclass
*******************************************************************************
*
* ThisJavaclassperformscalculationstodeterminethetimeof
* sunriseandsunsetgivenlat,long,anddate.
*
* Itisassumedthatthedataprovidedarewithinvalieranges
* (i.e.latitudebetween-90and+90,longitudebetween0and360,
* avaliddate,andtimezonebetween-14and+14.

*----------------------------------------------------------------------------*/
publicclassSunriseSunset
{

 //Declareandinitializevariables
 privatedouble dfLat;     //latitudefromuser
 privatedouble dfLon;     //latitudefromuser
 privateDate dateInput;    //date/timefromuser
 privatedouble dfTimeZone;    //timezonefromuser

 privateDate dateSunrise;   //dateandtimeofsunrise
 privateDate dateSunset;    //dateandtimeofsunset
 privateboolean bSunriseToday =false; //flagforsunriseonthisdate
 privateboolean bSunsetToday  =false; //flagforsunsetonthisdate
 privateboolean bSunUpAllDay  =false; //flagforsunupallday
 privateboolean bSunDownAllDay=false; //flagforsundownallday
 privateboolean bDaytime   =false; //flagfordaytime,given
           //hourandminindateInput
 privateboolean bSunrise=false;  //sunriseduringhourchecked
 privateboolean bSunset =false;  //sunsetduringhourchecked
 privateboolean bGregorian=false;  //flagforGregoriancalendar
 privateint  iJulian;    //Julianday
 private int  iYear;     //yearofdateofinterest
 private int  iMonth;     //monthofdateofinterest
 private int  iDay;     //dayofdateofinterest
 private int  iCount;     //asimplecounter
 private int  iSign;     //SUNUP.BAS:S
 privatedouble dfHourRise,dfHourSet; //hourofevent:SUNUP.BASH3
 privatedouble dfMinRise,dfMinSet; //minuteofevent:SUNUP.BASM3
 private double dfSinLat,dfCosLat;  //sinandcosoflatitude
 private double dfZenith;    //SUNUP.BASZ:Zenith
 private SimpleDateFormatdfmtDate;  //formattingfordatealone
 private SimpleDateFormatdfmtDateTime; //formattingfordateandtime
 private SimpleDateFormatdfmtYear;  //formattingforyear
 private SimpleDateFormatdfmtMonth;  //formattingformonth
 private SimpleDateFormatdfmtDay;  //formattingforday
 //ManyvariablesinSUNUP.BAShaveundocumentedmeanings,
 //andsoaretranslatedratherdirectlytoavoidconfusion:
 private double dfAA1=0,dfAA2=0; //SUNUP.BASA(2)
 private double dfDD1=0,dfDD2=0; //SUNUP.BASD(2)
 private double dfC0;     //SUNUP.BASC0
 private double dfK1;     //SUNUP.BASK1
 private double dfP;     //SUNUP.BASP
 private double dfJ;     //SUNUP.BASJ
 private double dfJ3;     //SUNUP.BASJ3
 private double dfA;     //SUNUP.BASA
 private double dfA0,dfA2,dfA5;  //SUNUP.BASA0,A2,A5
 private double dfD0,dfD1,dfD2,dfD5; //SUNUP.BASD0,D1,D2,D5
 private double dfDA,dfDD;    //SUNUP.BASDA,DD
 private double dfH0,dfH1,dfH2;  //SUNUP.BASH0,H1,H2
 private double dfL0,dfL2;    //SUNUP.BASL0,L2
 private double dfT,dfT0,dfTT;  //SUNUP.BAST,T0,TT
 private double dfV0,dfV1,dfV2;  //SUNUP.BASV0,V1,V2

 privateTimeZonetz=TimeZone.getTimeZone("GMT");

 
/******************************************************************************
* method:     SunriseSunset
*******************************************************************************
*
* ConstructorforSunriseSunsetclass.
*
*----------------------------------------------------------------------------*/
 SunriseSunset(
     doubledfLatIn,    //latitude
     doubledfLonIn,    //longitude
     Date dateInputIn,   //date
     doubledfTimeZoneIn   //timezone
     )
 {
  //Copyvaluessuppliedasagrumentstolocalvariables.
  dfLat  =dfLatIn;
  dfLon  =dfLonIn;
  dateInput =dateInputIn;
  dfTimeZone =dfTimeZoneIn;

  //Callthemethodtodothecalculations.
  doCalculations();

 }//endofclassconstructor


/******************************************************************************
* method:     doCalculations
*******************************************************************************
*
* MethodforperformingthecalculationsdoneinSUNUP.BAS.
*
*----------------------------------------------------------------------------*/
 privatevoiddoCalculations()
 {
  try
  {
   //Breakoutday,month,andyearfromdateprovided.
   //(Thisisnecesaryforthemathalgorithms.)

   dfmtYear =newSimpleDateFormat("yyyy");
   dfmtYear.setLenient(false);
   dfmtYear.setTimeZone(tz);

   dfmtMonth=newSimpleDateFormat("M");
   dfmtMonth.setLenient(false);
   dfmtMonth.setTimeZone(tz);

   dfmtDay  =newSimpleDateFormat("d");
   dfmtDay.setLenient(false);
   dfmtDay.setTimeZone(tz);

   iYear =Integer.parseInt( dfmtYear.format(dateInput));
   iMonth=Integer.parseInt(dfmtMonth.format(dateInput));
   iDay  =Integer.parseInt(  dfmtDay.format(dateInput));

   //Converttimezonehourstodecimaldays(SUNUP.BASline50)
   dfTimeZone=dfTimeZone/24.0;

   //NOTE:(7Feb2001)Hereisanon-standardpartofSUNUP.BAS:
   //It(andthisalgorithm)assumesthatthetimezoneis
   //positivewest,insteadofthestandardnegativewest.
   //ClassescallingSunriseSunsetwillbeassumingthat
   //timeszonesarespecifiedinnegativewest,soherethe
   //signischangedsothattheSUNUPalgorithmworks:
   dfTimeZone=-dfTimeZone;

   //Convertlongitudetofraction(SUNUP.BASline50)
   dfLon=dfLon/360.0;

   //ConvertcalendardatetoJuliandate:
   //Checktoseeifit"slaterthan1583:Gregoriancalendar
   //Whendeclared,bGregorianisinitializedtofalse.
   //**Considermakingaseparateclassofthisfunction.**
   if(iYear>=1583)bGregorian=true;
   //SUNUP.BAS1210
   dfJ=-Math.floor(7.0  //SUNUPusedINT,notfloor
       *(Math.floor(
             (iMonth+9.0)
             /12.0
            )+iYear
          )/4.0
       )
    //addSUNUP.BAS1240and1250forG=0
    +Math.floor(iMonth*275.0/9.0)
    +iDay
    +1721027.0
    +iYear*367.0;

   if(bGregorian)
   {
    //SUNUP.BAS1230
    if((iMonth-9.0)<0.0)iSign=-1;
    elseiSign=1;
    dfA=Math.abs(iMonth-9.0);
    //SUNUP.BAS1240and1250
    dfJ3=-Math.floor(
         (
      Math.floor(
       Math.floor(iYear
         +(double)iSign
           *Math.floor(dfA/7.0)
           )
           /100.0
          )+1.0
         )*0.75
        );
    //correctdfJasinSUNUP.BAS1240and1250forG=1
    dfJ=dfJ+dfJ3+2.0;
   }
   //SUNUP.BAS1290
   iJulian=(int)dfJ-1;

   //SUNUP.BAS60and70(seealsoline1290)
   dfT=(double)iJulian-2451545.0+0.5;
   dfTT=dfT/36525.0+1.0;    //centuriessince1900

   //Calculatelocalsiderealtimeat0hinzonetime
   //SUNUP.BAS410through460
   dfT0=(dfT*8640184.813/36525.0
     +24110.5
     +dfTimeZone*86636.6
     +dfLon*86400.0
     )
     /86400.0;
   dfT0=dfT0-Math.floor(dfT0); //NOTE:SUNUP.BASusesINT()
   dfT0=dfT0*2.0*Math.PI;
   //SUNUP.BAS90
   dfT=dfT+dfTimeZone;

   //SUNUP.BAS110:GetSun"sposition
   for(iCount=0;iCount<=1;iCount++) //Loopthruonlytwice
   {
    //CalculateSun"srightascensionanddeclination
    //  atthestartandendofeachday.
    //SUNUP.BAS910-1160:Fundamentalarguments
    //  fromvanFlandernandPulkkinen,1979

    //declarelocaltemporarydoublesforcalculations
    double dfGG;      //SUNUP.BASG
    double dfLL;      //SUNUP.BASL
    double dfSS;      //SUNUP.BASS
    double dfUU;      //SUNUP.BASU
    double dfVV;      //SUNUP.BASV
    double dfWW;      //SUNUP.BASW

    dfLL=0.779072+0.00273790931*dfT;
    dfLL=dfLL-Math.floor(dfLL);
    dfLL=dfLL*2.0*Math.PI;

    dfGG=0.993126+0.0027377785*dfT;
    dfGG=dfGG-Math.floor(dfGG);
    dfGG=dfGG*2.0*Math.PI;

    dfVV=  0.39785*Math.sin(dfLL)
      -0.01000*Math.sin(dfLL-dfGG)
      +0.00333*Math.sin(dfLL+dfGG)
      -0.00021*Math.sin(dfLL)*dfTT;

    dfUU=1
        -0.03349*Math.cos(dfGG)
      -0.00014*Math.cos(dfLL*2.0)
      +0.00008*Math.cos(dfLL);

    dfWW=-0.00010
      -0.04129*Math.sin(dfLL*2.0)
      +0.03211*Math.sin(dfGG)
      -0.00104*Math.sin(2.0*dfLL-dfGG)
      -0.00035*Math.sin(2.0*dfLL+dfGG)
      -0.00008*Math.sin(dfGG)*dfTT;

    //ComputeSun"sRAandDec;SUNUP.BAS1120-1140
    dfSS=dfWW/Math.sqrt(dfUU-dfVV*dfVV);
    dfA5=dfLL
       +Math.atan(dfSS/Math.sqrt(1.0-dfSS*dfSS));

    dfSS=dfVV/Math.sqrt(dfUU);
    dfD5=Math.atan(dfSS/Math.sqrt(1-dfSS*dfSS));     

    //Setvaluesandincrementt
    if(iCount==0)  //SUNUP.BAS125
    {
     dfAA1=dfA5;
     dfDD1=dfD5;
    }
    else     //SUNUP.BAS145
    {
     dfAA2=dfA5;
     dfDD2=dfD5;
    }
    dfT=dfT+1.0;  //SUNUP.BAS130
   } //endofGetSun"sPositionforloop

   if(dfAA2<dfAA1)dfAA2=dfAA2+2.0*Math.PI;
               //SUNUP.BAS150

   dfZenith=Math.PI*90.833/180.0;   //SUNUP.BAS160
   dfSinLat=Math.sin(dfLat*Math.PI/180.0); //SUNUP.BAS170
   dfCosLat=Math.cos(dfLat*Math.PI/180.0); //SUNUP.BAS170

   dfA0=dfAA1;         //SUNUP.BAS190
   dfD0=dfDD1;         //SUNUP.BAS190
   dfDA=dfAA2-dfAA1;       //SUNUP.BAS200
   dfDD=dfDD2-dfDD1;       //SUNUP.BAS200

   dfK1=15.0*1.0027379*Math.PI/180.0;  //SUNUP.BAS330

   //Initializesunriseandsunsettimes,andothervariables
   //hrandminaresettoimpossibletimestomakeerrorsobvious
   dfHourRise=99.0;
   dfMinRise =99.0;
   dfHourSet =99.0;
   dfMinSet  =99.0;
   dfV0=0.0;  //initializationimpliedbyabsenceinSUNUP.BAS
   dfV2=0.0;  //initializationimpliedbyabsenceinSUNUP.BAS

   //TesteachhourtoseeiftheSuncrossesthehorizon
   //  andwhichwayitisheading.
   for(iCount=0;iCount<24;iCount++)   //SUNUP.BAS210
   {
    double tempA;        //SUNUP.BASA
    double tempB;        //SUNUP.BASB
    double tempD;        //SUNUP.BASD
    double tempE;        //SUNUP.BASE

    dfC0=(double)iCount;
    dfP=(dfC0+1.0)/24.0;    //SUNUP.BAS220
    dfA2=dfAA1+dfP*dfDA;     //SUNUP.BAS230
    dfD2=dfDD1+dfP*dfDD;     //SUNUP.BAS230
    dfL0=dfT0+dfC0*dfK1;     //SUNUP.BAS500
    dfL2=dfL0+dfK1;       //SUNUP.BAS500
    dfH0=dfL0-dfA0;       //SUNUP.BAS510
    dfH2=dfL2-dfA2;       //SUNUP.BAS510
    //hourangleathalfhour
    dfH1=(dfH2+dfH0)/2.0;    //SUNUP.BAS520
    //declinationathalfhour
    dfD1=(dfD2+dfD0)/2.0;    //SUNUP.BAS530

    //SetvalueofdfV0onlyifthisisthefirsthour,
    //otherwise,itwillgetsettothelastdfV2(SUNUP.BAS250)
    if(iCount==0)       //SUNUP.BAS550
    { 
     dfV0=dfSinLat*Math.sin(dfD0)
      +dfCosLat*Math.cos(dfD0)*Math.cos(dfH0)
      -Math.cos(dfZenith);   //SUNUP.BAS560
    }
    else
     dfV0=dfV2; //Thatis,dfV2fromtheprevioushour.

    dfV2=dfSinLat*Math.sin(dfD2)
      +dfCosLat*Math.cos(dfD2)*Math.cos(dfH2)
      -Math.cos(dfZenith);   //SUNUP.BAS570

    //ifdfV0anddfV2havethesamesign,thenproceedtonexthr
    if(
     (dfV0>=0.0&&dfV2>=0.0)  //botharepositive
     ||        //or
     (dfV0<0.0&&dfV2<0.0)  //botharenegative
      )
    {
     //Breakiterationandproceedtotestnexthour
     dfA0=dfA2;       //SUNUP.BAS250
     dfD0=dfD2;       //SUNUP.BAS250
     continue;        //SUNUP.BAS610
    }

    dfV1=dfSinLat*Math.sin(dfD1)
     +dfCosLat*Math.cos(dfD1)*Math.cos(dfH1)
     -Math.cos(dfZenith);    //SUNUP.BAS590

    tempA=2.0*dfV2-4.0*dfV1+2.0*dfV0;
               //SUNUP.BAS600
    tempB=4.0*dfV1-3.0*dfV0-dfV2;  //SUNUP.BAS600
    tempD=tempB*tempB-4.0*tempA*dfV0; //SUNUP.BAS610

    if(tempD<0.0)
    {
     //Breakiterationandproceedtotestnexthour
     dfA0=dfA2;       //SUNUP.BAS250
     dfD0=dfD2;       //SUNUP.BAS250
     continue;        //SUNUP.BAS610
    }

    tempD=Math.sqrt(tempD);     //SUNUP.BAS620

    //Determineoccurenceofsunriseorsunset.

    //Flagstoidentifyoccurrenceduringthisdayare
    //bSunriseTodayandbSunsetToday,andareinitializedfalse.
    //Thesearesettrueonlyifsunriseorsunsetoccurs
    //atanypointinthehourlyloop.Neversettofalse.

    //Flagstoidentifyoccurrenceduringthishour:
    bSunrise=false;    //resetbeforetest
    bSunset =false;    //resetbeforetest

    if(dfV0<0.0&&dfV2>0.0) //sunriseoccursthishour
    {
     bSunrise=true;   //SUNUP.BAS640
     bSunriseToday=true;  //sunriseoccurredtoday
    }

    if(dfV0>0.0&&dfV2<0.0) //sunsetoccursthishour
    {
     bSunset=true;    //SUNUP.BAS660
     bSunsetToday=true;  //sunsetoccurredtoday
    }

    tempE=(tempD-tempB)/(2.0*tempA);
    if(tempE>1.0||tempE<0.0) //SUNUP.BAS670,680
     tempE=(-tempD-tempB)/(2.0*tempA);     

    //Setvaluesofhourandminuteofsunsetorsunrise
    //onlyifsunrise/setoccurredthishour.
    if(bSunrise)
    {
     dfHourRise=Math.floor(dfC0+tempE+1.0/120.0);
     dfMinRise =Math.floor(
           (dfC0+tempE+1.0/120.0
              -dfHourRise
           )
           *60.0
           );
    }

    if(bSunset)
    {
     dfHourSet =Math.floor(dfC0+tempE+1.0/120.0);
     dfMinSet  =Math.floor(
           (dfC0+tempE+1.0/120.0
              -dfHourSet
           )
           *60.0
           );
    }

    //Changesettingsofvariablesfornextloop
    dfA0=dfA2;        //SUNUP.BAS250
    dfD0=dfD2;        //SUNUP.BAS250

   } //endoflooptestingeachhourforanevent 

   //Afterhavingcheckedallhours,setflagsifnoriseorset
   //bSunUpAllDayandbSundownAllDayareinitializedasfalse
   if(!bSunriseToday&&!bSunsetToday)
   {
    if(dfV2<0.0)
     bSunDownAllDay=true;
    else
     bSunUpAllDay=true;
   }

   //LoaddateSunrisewithdata
   dfmtDateTime=newSimpleDateFormat("dMyyyyHH:mmz");
   if(bSunriseToday)
   {
    dateSunrise=dfmtDateTime.parse(iDay
          +""+iMonth
          +""+iYear
          +""+(int)dfHourRise
          +":"+(int)dfMinRise
          +"GMT");
   }

   //LoaddateSunsetwithdata
   if(bSunsetToday)
   {
    dateSunset=dfmtDateTime.parse(iDay
          +""+iMonth
          +""+iYear
          +""+(int)dfHourSet
          +":"+(int)dfMinSet
          +"GMT");
   }
  }//endoftry

  //Catcherrors
  catch(ParseExceptione)
  {
   System.out.println("\nCannotparsedate");
   System.out.println(e);
   System.exit(1);
  }//endofcatch

 }

 
/******************************************************************************
* method:     getSunrise()
*******************************************************************************
*
*  Getsthedateandtimeofsunrise. Ifthereisnosunrise,returnsnull.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicDategetSunrise()
 {
  if(bSunriseToday)
   return(dateSunrise);
  else
   return(null);
 }


/******************************************************************************
* method:     getSunset()
*******************************************************************************
*
*  Getsthedateandtimeofsunset. Ifthereisnosunset,returnsnull.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicDategetSunset()
 {
  if(bSunsetToday)
   return(dateSunset);
  else
   return(null);
 }


/******************************************************************************
* method:     isSunrise()
*******************************************************************************
*
*  Returnsabooleanidentifyingiftherewasasunrise.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicbooleanisSunrise()
 {
  return(bSunriseToday);
 }


/******************************************************************************
* method:     isSunset()
*******************************************************************************
*
*  Returnsabooleanidentifyingiftherewasasunset.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicbooleanisSunset()
 {
  return(bSunsetToday);
 }


/******************************************************************************
* method:     isSunUp()
*******************************************************************************
*
*  Returnsabooleanidentifyingifthesunisupallday.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicbooleanisSunUp()
 {
  return(bSunUpAllDay);
 }


/******************************************************************************
* method:     isSunDown()
*******************************************************************************
*
*  Returnsabooleanidentifyingifthesunisdownallday.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicbooleanisSunDown()
 {
  return(bSunDownAllDay);
 }


/******************************************************************************
* method:     isDaytime()
*******************************************************************************
*
*  Returnsabooleanidentifyingifitisdaytimeatthehourcontainedin
* theDateobjectpassedtoSunriseSunsetonconstruction.
*    
* MemberofSunriseSunsetclass
*    
*--------------------------------------------------------------------------*/
 publicbooleanisDaytime()
 {
  //Determineifitisdaytime(atsunriseorlater)
  // ornighttime(atsunsetorlater)atthelocationofinterest
  // butexpressedinthetimezonerequested.
  if(bSunriseToday&&bSunsetToday) //sunriseandsunset
  {
   if(dateSunrise.before(dateSunset)) //sunrise<sunset
   {
    if(
     ( 
      dateInput.after(dateSunrise)

      dateInput.equals(dateSunrise)
     )
     &&
     dateInput.before(dateSunset)
      )
     bDaytime=true;
    else
    bDaytime=false;
    }
   else //sunrisecomesaftersunset(inoppositetimezones)
   {
    if(
     ( 
      dateInput.after(dateSunrise)

      dateInput.equals(dateSunrise)
     )
     ||   //useORratherthanAND
     dateInput.before(dateSunset)
      )
     bDaytime=true;
    else
    bDaytime=false;
    }
  }
  elseif(bSunUpAllDay)    //sunisupallday
   bDaytime=true;
  elseif(bSunDownAllDay)    //sunisdownallday
   bDaytime=false;
  elseif(bSunriseToday)    //sunrisebutnosunset
  {
   if(dateInput.before(dateSunrise))
    bDaytime=false;
   else
    bDaytime=true;
  }
  elseif(bSunsetToday)    //sunsetbutnosunrise
  {
   if(dateInput.before(dateSunset))
    bDaytime=true;
   else
    bDaytime=false;
  }
  elsebDaytime=false;     //thisshouldneverexecute

  return(bDaytime);
 }


}//endofclass

/*-----------------------------------------------------------------------------
*       endofclass
*----------------------------------------------------------------------------*/