24. Conversion Formula for solar term and calendar date of any year

Source: Internet
Author: User

There is a certain error in the formula, but it will be within several minutes between and...
Many calendar scripts use the hour () as the start of a day, so that a day will be added after...

 

# Include <stdio. h> <br/> # include <stdlib. h> <br/> static const double x_1900_1_6_2_5 = 693966.08680556; <br/> double get_solar_term (INT y, int N) <br/>{< br/> static const int terminfo [] ={< br/> 0, 21208,424 67, 63836,853 37, 107014, <br/> 128867,150921, 173149,195551, 218072,240693, <br/> 263343,285989, 308563,331033, 353350,375494, <br/> average, minimum 795,462224, 482.16,504758 <br/>}; <br/> RET Urn x_1900_1_6_2_5 + 365.2422 * (y-1900) + terminfo [N]/(60. * 24); <br/>}< br/> int format_date (unsigned _ days, char * result); <br/> int main (INT argc, char * argv []) <br/>{< br/> static const char * solar_term_name [] ={< br/> "Xiao Han", "da Han", "Li Chun ", "Rain", <br/> "stunned", "Spring Equinox", "Qingming", "Gu Yu", <br/> "lixia", "xiaoman", "Mango ", "Summer Solstice", <br/> "Summer heat", "Summer heat", "Autumn Heat", "Summer heat", <br/> "White Dew", "Autumn Equinox", "Cold Dew ", "Frost down", <br/> "Winter", "light snow", "heavy snow", "Winter Solstice" <br/>}; <br/> char Str _ D [2, 100]; <br/> int year = 2008, I; <br/> If (argc = 2) <br/>{< br/> year = atoi (argv [1]); <br/> If (year <1900 | year> 2099) <br/> year = 2008; <br/>}< br/> for (I = 0; I <24; ++ I) <br/>{< br/> format_date (unsigned) get_solar_term (year, I), str_d); <br/> printf ("% s: % s/n ", solar_term_name [I], str_d); <br/>}</P> <p> return 0; <br/>}< br/> int format_date (unsigned _ days, Cha R * result) <br/>{< br/> static const int mdays [] = {0, 31, 59, 90,120,151,181,212,243,273,304,334,365}; <br/> int y, m, d, diff; <br/> unsigned days; <br/> days = 100 * (_ days-_ days/(3652425l/(3652425l-3652400l ))); <br/> Y = days/36524; days % = 36524; <br/> M = 1 + days/3044;/* [1 .. 12] */<br/> d = 1 + (days % 3044)/100;/* [1 .. 31] */<br/> diff = y * 365 + Y/4-y/100 + Y/400 + mdays [M-1] + d -(M <= 2 & (Y & 3) = 0) & (Y % 100 )! = 0 | Y % 400 = 0)-_ days; <br/> If (diff> 0 & diff> = d )/*~ 0.5% */<br/>{< br/> If (M = 1) <br/>{< br/> -- y; M = 12; <br/> d = 31-(diff-D ); <br/>}< br/> else <br/> {<br/> d = mdays [M-1]-(diff-D ); <br/> If (-- M = 2) <br/> D + = (Y & 3) = 0) & (Y % 100 )! = 0 | Y % 400 = 0 ); <br/>}< br/> else <br/> {<br/> If (D-= diff)> mdays [m]) /*~ 1.6% */<br/> {<br/> If (M = 2) <br/> {<br/> If (Y & 3) = 0) & (Y % 100 )! = 0 | Y % 400 = 0) <br/>{< br/> If (D! = 29) <br/> M = 3, D-= 29; <br/>}< br/> else <br/>{< br/> M = 3, d-= 28; <br/>}< br/> else <br/>{< br/> D-= mdays [m]; <br/> If (M ++ = 12) <br/> ++ y, M = 1; <br/>}< br/> return sprintf (result, "% 04d-% 02d-% 02d", Y, m, d); <br/>}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.