SunCalc是一个微小的BSD授权的JavaScript库,用于计算太阳位置、日照阶段(日出、日落、黄昏等时间)、月亮位置和月相。
使用示例:
//gettoday'ssunlighttimesforLondonvartimes=SunCalc.getTimes(newDate(),51.5,-0.1);//formatsunrisetimefromtheDateobjectvarsunriseStr=times.sunrise.getHours()+':'+times.sunrise.getMinutes();//getpositionofthesun(azimuthandaltitude)attoday'ssunrisevarsunrisePos=SunCalc.getPosition(times.sunrise,51.5,-0.1);//getsunriseazimuthindegreesvarsunriseAzimuth=sunrisePos.azimuth*180/Math.PI;SunCalc也可用作NPM包:
$npminstallsuncalcvarSunCalc=require('suncalc');
评论