天黑时间跟经度还是纬度有关_根据经纬度计算日出、日落、中天、天亮、天黑和昼长时间...

importjava.io.IOException;importjava.util.Date;importjava.util.HashMap;importjava.util.Map;importjava.util.Properties;public classDayTime {private staticProperties propt;private static double RAD = 180.0 * 3600 /Math.PI;private static doublemidDayTime;private static doubledawnTime;private static String codeStr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";static{

propt= newProperties();try{

propt.load(DayTime.class.getClassLoader().getResourceAsStream("jwd.properties"));

}catch(IOException e) {

e.printStackTrace();

}

}

@SuppressWarnings("deprecation")public static Mapdailytime(String area) {

Date date= newDate();return dailytime(area, date.getYear(), date.getMonth(), date.getDay(), 0, 0, 0,8.0);

}public static Map dailytime(String area, int year, int month, int day, int hour, int min, int sec,doubletz) {

Map map = new HashMap();

String jwd=decodeJWD(area);

System.out.println(jwd);

Double wd= (Double.parseDouble(jwd.substring(0, 2)) + Double.parseDouble(jwd.substring(2, 4)) / 60) / 180 *Math.PI;

Double jd= -(Double.parseDouble(jwd.substring(4, 7)) + Double.parseDouble(jwd.substring(7)) / 60) / 180 *Math.PI;double richu = timeToDouble(year, month, day, hour, min, sec) - 2451544.5;for (int i = 0; i < 10; i++)

richu= sunRiseTime(richu, jd, wd, tz / 24);//逐步逼近法算10次//日出

map.put(DayTimeType.SUNRISE, doubleToStr(richu));//日落

map.put(DayTimeType.SUNSET, doubleToStr(midDayTime + midDayTime -richu));//中天

map.put(DayTimeType.MIDTIME, doubleToStr(midDayTime));//天亮

map.put(DayTimeType.DAWNTIME, doubleToStr(dawnTime));//天黑

map.put(DayTimeType.NIGHTTIME, doubleToStr(midDayTime + midDayTime -dawnTime));//昼长

map.put(DayTimeType.DAYTIME, doubleToStr((midDayTime - dawnTime) * 2 - 0.5));returnmap;

}//加密

public staticString decodeJWD(String encode) {

StringBuilder jwd= newStringBuilder();for (int i = 0; i < 4; i++)if (2 ==i)

jwd.append(String.format("%03d", codeStr.indexOf(encode.charAt(i)) + 73));elsejwd.append(String.format("%02d", codeStr.indexOf(encode.charAt(i))));returnjwd.toString();

}//解密

public staticString encodeJWD(Integer decode) {

StringBuilder jwd= newStringBuilder();int i = 230811316;int ge = i % 100;int shi = i % 100000 -ge;int bai = i % 10000000 -shi;int qian = i % 1000000000 -bai;

shi= shi / 100 - 73;

bai= bai / 100000;

qian= qian / 10000000;jwd.append(codeStr.charAt(qian)).append(codeStr.charAt(bai)).append(codeStr.charAt(shi)).append(codeStr.charAt(ge));returnjwd.toString();

}/***

*@paramdate

* 儒略日平午

*@paramlo

* 地理经度

*@paramla

* 地理纬度

*@paramtz

* 时区

*@return太阳升起时间*/

public static Double sunRiseTime(double date, double lo, double la, doubletz) {

date= date -tz;//太阳黄经以及它的正余弦值

double t = date / 36525;double j =sunHJ(t);//太阳黄经以及它的正余弦值

double sinJ =Math.sin(j);double cosJ =Math.cos(j);//其中2*PI*(0.7790572732640 + 1.00273781191135448*jd)恒星时(子午圈位置)

double gst = 2 * Math.PI * (0.779057273264 + 1.00273781191135 * date) + (0.014506 + 4612.15739966 * t + 1.39667721 * t * t) /RAD;double E = (84381.406 - 46.836769 * t) / RAD; //黄赤交角

double a = Math.atan2(sinJ * Math.cos(E), cosJ);//'太阳赤经

double D = Math.asin(Math.sin(E) * sinJ); //太阳赤纬

double cosH0 = (Math.sin(-50 * 60 / RAD) - Math.sin(la) * Math.sin(D)) / (Math.cos(la) * Math.cos(D)); //日出的时角计算,地平线下50分

double cosH1 = (Math.sin(-6 * 3600 / RAD) - Math.sin(la) * Math.sin(D)) / (Math.cos(la) * Math.cos(D)); //天亮的时角计算,地平线下6度,若为航海请改为地平线下12度//严格应当区分极昼极夜,本程序不算

if (cosH0 >= 1 || cosH0 <= -1)return -0.5;//极昼

double H0 = -Math.acos(cosH0); //升点时角(日出)若去掉负号 就是降点时角,也可以利用中天和升点计算

double H1 = -Math.acos(cosH1);double H = gst - lo - a; //太阳时角

midDayTime = date - degree(H) / Math.PI / 2 + tz; //中天时间

dawnTime = date - degree(H - H1) / Math.PI / 2 + tz;//天亮时间

return date - degree(H - H0) / Math.PI / 2 + tz; //日出时间,函数返回值

}/*** 保证角度∈(-π,π)

*

*@paramag

*@returnag*/

public static Double degree(doubleag) {

ag= mod(ag, 2 *Math.PI);return ag <= -Math.PI ? ag + 2 * Math.PI : ag > Math.PI ? ag - 2 *Math.PI : ag;

}public static Double mod(double num1, doublenum2) {

num2=Math.abs(num2);//只是取决于Num1的符号

return num1 >= 0 ? num1 - ((int) (num1 / num2)) * num2 : ((int) (Math.abs(num1) / num2)) * num2 -Math.abs(num1);

}/***@paramt

* 儒略世纪数

*@return太阳黄经*/

public static Double sunHJ(doublet) {

t= t + (32.0 * (t + 1.8) * (t + 1.8) - 20) / 86400.0 / 36525.0;//儒略世纪年数,力学时

double j = 48950621.66 + 6283319653.318 * t + 53 * t * t - 994 + 334166 * Math.cos(4.669257 + 628.307585 * t) + 3489 * Math.cos(4.6261 + 1256.61517 * t) + 2060.6 * Math.cos(2.67823 + 628.307585 * t) *t;return j / 10000000;

}/*** 儒略日的计算

*

*@paramy

* 年

*@paramM

* 月

*@paramd

* 日

*@paramh

* 小时

*@paramm

* 分

*@params

* 秒

*@returnint*/

public static int timeToDouble(int y, int M, int d, int h, int m, ints) {double time = 0;if (M <= 2) {

M+= 12;

y-= 1;

}if (y * 372 + M * 31 + d >= 588829) {

time= (int) (y / 100);

time= 2 - time + (int) (time / 4);

}

time+= (int) Math.round(365.25 * (y + 4716) + 0.01) + (int) (30.60001 * (M + 1)) + d + (h * 3600 + m * 60 + s) / (24 * 3600) - 1524.5;return (int) Math.round(time);

}public static String doubleToStr(doubletime) {double t = time + 0.5;

t= (t - (int) t) * 24;int h = (int) t;

t= (t - h) * 60;int m = (int) t;

t= (t - m) * 60;int s = (int) t;return h + ":" + m + ":" +s;

}public static voidmain(String[] args) {//System.out.println(decodeJWD("N3dS肇庆"));//String jwd = decodeJWD("N3dS肇庆");//Double wd = (Double.parseDouble(jwd.substring(0, 2)) +//Double.parseDouble(jwd.substring(2, 4)) / 60) / 180 * Math.PI;//Double jd = -(Double.parseDouble(jwd.substring(4, 7)) +//Double.parseDouble(jwd.substring(7)) / 60) / 180 * Math.PI;//double richu = timeToDouble(2012, 6, 25, 0, 0, 0) - 2451544.5;//System.out.println(richu + " " + timeToDouble(2012, 6, 25, 0, 0, 0));//richu = sunRiseTime(richu, jd, wd, 8.0 / 24);//System.out.println(richu);//richu = sunRiseTime(richu, jd, wd, 8.0 / 24);//逐步逼近法算两次//System.out.println(doubleToStr(richu));

String t = "03";

System.out.println(Integer.parseInt(t));

System.out.println(propt.getProperty("HI"));

String[] strs= propt.getProperty("HI").split(" ");for (int i = 1; i < strs.length; i++) {

System.out.println(strs[i]+ " 日出 " +dailytime(strs[i]).get(DayTimeType.SUNRISE));

System.out.println(strs[i]+ " 日落" +dailytime(strs[i]).get(DayTimeType.SUNSET));

System.out.println(strs[i]+ " 中天" +dailytime(strs[i]).get(DayTimeType.MIDTIME));

System.out.println(strs[i]+ " 天亮" +dailytime(strs[i]).get(DayTimeType.DAWNTIME));

System.out.println(strs[i]+ " 天黑" +dailytime(strs[i]).get(DayTimeType.NIGHTTIME));

System.out.println(strs[i]+ " 昼长" +dailytime(strs[i]).get(DayTimeType.DAYTIME));

}

System.out.println(encodeJWD(230811316));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值