我正在构建一个可以告诉您中文符号的应用程序。我环顾四周,但只找到了图表(从1900年到2020年),没有逻辑来创造更有活力的东西。
没有确定中国十二生肖的逻辑吗?
答案 0 :(得分:5)
这是否回答了你的问题:
public string get_ChineseZodiac(System.DateTime date)
{
System.Globalization.EastAsianLunisolarCalendar cc =
new System.Globalization.ChineseLunisolarCalendar();
int sexagenaryYear = cc.GetSexagenaryYear(date);
int terrestrialBranch = cc.GetTerrestrialBranch(sexagenaryYear);
// string[] years = "rat,ox,tiger,hare,dragon,snake,horse,sheep,monkey,fowl,dog,pig".Split(',');
// string[] years = "Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat,Monkey,Rooster,Dog,Pig".Split(',');
// string[] years = new string[]{ "rat", "ox", "tiger", "hare", "dragon", "snake", "horse", "sheep", "monkey", "fowl", "dog", "pig" };
string[] years = new string[]{ "Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig" };
return years[terrestrialBranch - 1];
} // End Function get_ChineseZodiac
答案 1 :(得分:2)
使用计算器
2013-4=2009
2009/12= 167.41666
167*12=2004
2009-2004=5 (5 is snake which was the animal for 2013)
答案 2 :(得分:1)
维基百科提到了2044年。
http://en.wikipedia.org/wiki/Chinese_zodiac
以鼠年代为例(1984年以后的几年),它看起来像是每次循环:
383, 353, 353, 383, 354 days
请注意,最后一个周期为354
,这很可能是由于闰年。也许使用这个公式,你可以在任何一年到2100年左右锻炼。
我使用以下T-SQL
推断出这些数字
select DATEDIFF(D,'02/2/1984', '02/19/1985')
select DATEDIFF(D,'02/19/1996', '02/6/1997')
select DATEDIFF(D,'02/7/2008', '01/25/2009')
select DATEDIFF(D,'01/25/2020', '02/11/2021')
select DATEDIFF(D,'02/11/2032', '01/30/2033')
答案 3 :(得分:1)
如果您认真寻找一种计算中国十二生肖年份的非表格机制,那么我建议您查看'Calendrical Calculations, 3rd Edition'哪个(LISP)代码来处理中国农历新年的计算,以及,推断< 相关动物的年份>是直截了当的。那本书涵盖了许多日历系统,是一本有趣的读物。作为一个月历太阳历,中国历法非常复杂;数学变得非常详细。
但是,使用表格可能更简单,也可能更紧凑,代码更明确。
答案 4 :(得分:1)
用它来计算年份。
<?php
$year = 2013;
switch (($year - 4) % 12) {
case 0: $zodiac = 'Rat'; break;
case 1: $zodiac = 'Ox'; break;
case 2: $zodiac = 'Tiger'; break;
case 3: $zodiac = 'Rabbit'; break;
case 4: $zodiac = 'Dragon'; break;
case 5: $zodiac = 'Snake'; break;
case 6: $zodiac = 'Horse'; break;
case 7: $zodiac = 'Goat'; break;
case 8: $zodiac = 'Monkey'; break;
case 9: $zodiac = 'Rooster'; break;
case 10: $zodiac = 'Dog'; break;
case 11: $zodiac = 'Pig'; break;
}
echo "{$year} is the year of the {$zodiac}.<br />";
?>
答案 5 :(得分:0)
总是存在一个问题,即测试和验证的速度更快。
在calculla上开发chinese zodiac calculator时,我们决定使用查找表 - 因为这比实际测试任何算法更快更方便代码(即使algo可能很简单,你仍然需要时间测试它。)
这个查找不是一张大表,你可以从我们网站的源代码中获得javascript代码。
答案 6 :(得分:0)
首先,您必须完全按照以下步骤创建十二生肖数组
DECLARE sign : [array(1.....12)]
DECLARE year : INTEGER
sign(1) ← "Rat"
sign(2) ← "Ox"
sign(3) ← "Tiger"
sign(4) ← "Rabbit"
sign(5) ← "Dragon"
sign(6) ← "Snake"
sign(7) ← "Horse"
sign(8) ← "Goat"
sign(9) ← "Monkey"
sign(10) ← "Rooster"
sign(11) ← "Dog"
sign(12) ← "Pig"
DECLARE X, Y, N : INTEGER
X ← (year - 4)
Y ← (X DIV 12) // DIV return only the natural number
Y ← (Y * 12)
N ← N + 1
OUTPUT sign(N)
答案 7 :(得分:0)
Public Function ChineseSign(ByVal DoB As Date) As String
Dim CSign As String = ""
Dim YearSign As New Short
YearSign = Year(DoB) Mod 12
'// Uncomment the following to use Feb 12th as New Year calculation //
'If Month(DoB) = 1 Then
'YearSign = YearSign - 1
'If YearSign = 0 Then YearSign = 12
'ElseIf Month(DoB) = 2 And DoB.Day < 12 Then
'YearSign = YearSign - 1
'If YearSign = 0 Then YearSign = 12
'End If
Select Case YearSign
Case 1
CSign = "Rooster"
Case 2
CSign = "Dog"
Case 3
CSign = "Pig (Boar)"
Case 4
CSign = "Rat"
Case 5
CSign = "Ox"
Case 6
CSign = "Tiger"
Case 7
CSign = "Rabbit"
Case 8
CSign = "Dragon"
Case 9
CSign = "Snake"
Case 10
CSign = "Horse"
Case 11
CSign = "Goat"
Case 12
CSign = "Monkey"
End Select
Select Case CSign
Case "Ox"
Return "an " & CSign
Case Else
Return "a " & CSign
End Select
End Function