二十四节气算法

2018-01-19 20:52:31
Reading:326
二十四节气算法
2013年09月10日

使用说明: 主方法为Lunar24Class.getSoralTerm();

如: Alert.show(Lunar24Class.getSoralTerm(2011,3,21));
则可得到 2011-3-21的节气为"春分"..如果当日不是节气,返回空字符串

调用范例: 循环2011年的所有节气
function addJyecyea(ac:ArrayCollection):void{
 for(var i=1;i<=12;i++){
  for(var j=1;j<=31;j++){
   var jc:String=Lunar24Class.getSoralTerm(2011,i,j);
   if(jc!=""){
    //DOING SOMETHING...
   }
  }
 }
}
--------------------源码------------------------

package{
 public class Lunar24Class{
  public function Lunar24Class(){}

  public static var solarTerm:Array = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至");

  private static var sTermInfo:Array = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758);

  //===== 某年的第n个节气为几日(从0小寒起算)
  private static function sTerm(y:int, n:int):int{
   var offDate:Date = new Date((31556925974.7 * (y - 1900) + sTermInfo[n] * 60000) + Date.UTC(1900, 0, 6, 2, 5));
   return (offDate.getUTCDate());
  }

  /** 核心方法 根据日期(y年m月d日)得到节气 */
  public static function getSoralTerm( y:int, m:int , d:int):String {
   var solarTerms:String;
   if (d == sTerm(y, (m - 1) * 2))
    solarTerms = solarTerm[(m - 1) * 2];
   else if (d == sTerm(y, (m - 1) * 2 + 1))
    solarTerms = solarTerm[(m - 1) * 2 + 1];
   else {
    // 到这里说明非节气时间
    solarTerms = "";
   }
   return solarTerms;
  }
 }
}

About

When I was young
I'd listen to the radio
Waiting for my favorite songs
When they played I'd sing along
It made me smile
Those were such happy times
And not so long ago
How I wondered where they'd gone
But they're back again
Just like a long lost friend
All the songs I loved so well