精華區beta mud 關於我們 聯絡資訊
作者 Kenny.bbs@bbs.cis.nctu.edu.tw (小祥), 看板 mud 標題 Re: About MudOS 陰陽曆轉換程式 時間 交大資科_BBS (Sun Mar 9 16:24:27 1997) 路徑 maple!news.cs.nthu!news.cis.nctu!cis_nctu ─────────────────────────────────────── ==> 在 jjchen.bbs@bbs.ntnu.edu.tw (陳金進) 的文章中提到: > 鑒於泥巴世界的背景為中國古代者不少, 可惜沒有一個陰曆曆法, > 特藉他人的程式轉為 MudOS 版本, 希望提供大家傳播使用 > wade@Fantasy.Space > jjchen@ice.ntnu.edu.tw 我也來貢獻一點… (改自 Wade 作品) #define BASE (723916800) // Dec 10 00:00:00 1992 #define DAY (86400) #define MONTHS ({"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",\ "Sep", "Oct", "Nov", "Dec"}) // 求此西曆年是否為閏年, 返回 0 為平年, 1 為閏年 int isleap(int year) { if (year%400 == 0) return 1; else if (year%100 == 0) return 0; else if (year%4 == 0) return 1; else return 0; } // isleap() // 將時間字串轉換成距 Dec 10 00:00:00 1992 的秒數 int gtime(string time) { string week, month; int day, hour, minute, second, year, m, y, seconds=BASE; /* 西曆年每月之日數 */ int *SolarCal=({31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}); if (!time || sscanf(time, "%s %s %d %d:%d:%d %d", week, month, day, hour, minute, second, year)!=7) return -1; if (year > 1992) seconds+=DAY*22; for (y=1993; y<year; y++) if (isleap(y)) seconds+=DAY*366; else seconds+=DAY*365; for (m=member_array(month, MONTHS)-1; m>=0; m--) { seconds += DAY*SolarCal[m]; if (isleap(year) && m==1) seconds += DAY; } seconds += DAY*(day-1); seconds += 3600*hour; seconds += 60*minute; seconds += second; return seconds; } // gtime()