Home>

Birthday characterReferred to as eight characters,Refers to the date of the calendar when a person is born;There were a total of four pillars in the year, month, and year.Two words per column,Eight words in total.It is said. The birthday character occupies an important position in the folk beliefs of the Han nationality.Based on this, the ancient Chinese astrological family estimated the fate of people.In this article, we will use c#to calculate the birthday character.

form1.cs

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
namespace brithdayeigth
{
  public partial class form1:form
  {
    public form1 ()
    {
      initializecomponent ();
    }
    public static string [] date={
     "Jia Zi", "Yi Chou", "Bing Yin", "Ding Yi", "Wu Chen", "Ji Yi", "Geng Wu", "Xin Wei", "Ren Shen", "Gui Yi",     "Meiwu", "Yihai", "Bingzi", "Ding Chou", "Wuyin", "Yiyi", "Gengchen", "Xinyi", "Renwu", "Guiwei", "Jiashen", "Yiyi", "Bingyi", "Dinghai", "Wujizi", "Jihou", "Gengyin", "Xinyi", "Renchen", "Guyi", "Jiawu", " "Yiwei", "Bingshen", "Dingyi", "Xueyi", "jihai", "Gengzi", "Xin Chou", "renyin", "guiyi", "jiachen", "yiyi" , "Bing Wu", "Ding Wei", "Wu Shen", "Yu Yi", "Geng Yi", "Xin Hai", "Xin Zi", "Gu Chou", "Jia Yin", "Yi Yi", "Bing "Chen", "Ding Ye", "Wu Wu", "Ji Wei", "Geng Shen", "Xin Ye", "Ren Ye", "Gui Hai"
                   };
    public int yearzi=0;
    private void btnok_click (object sender, eventargs e)
    {
      datetime dt=day.value;
      int year=dt.year;
      int moon=dt.month;
      int date=dt.dayofyear;
      messagebox.show ("test:" + (year%60-3) + ":" + moon + ":" + date);
      //Call the method to get the birthday
      string yearzi=yearz (year);
      string moonzi=moonz (moon, year);
      string dayzi=dayei (year, date);
      int hour=int.parse (hourdate.text);
     string hourzi=hours (hour, date, year);
      txtbrithday.text=yearzi + "" + moonzi + "" + dayzi + "" + hourzi;
    }
    private void form1_load (object sender, eventargs e)
    {
    }
    //How to get the birthday
    public string yearz (int y) {
      int yearzie=yearnum (y);
      return date [yearzie-1];
    }
    public string moonz (int m, int year) {
      int yearzie=yearnum (year);
      if (yearzie>= 12)
      {
        if (yearzie%10 == 6 || yearzie%10 == 1)
        {
          return date [2 + m-1];
        }
        else if (yearzie%10 == 2 || yearzie%10 == 7) {
          return date [14 + m-1];
        }
        else if (yearzie%10 == 3 || yearzie%10 == 8)
        {
          return date [26 + m-1];
        }
        else if (yearzi%10 == 4 || yearzi%10 == 9)
        {
          return date [38 + m-1];
        }
        else if (yearzie%10 == 5 || yearzie%10 == 0)
        {
          return date [50 + m-1>60?(m-11):49 + m];
        }
      }
      else
      {
        if (yearzie == 6 || yearzie == 1)
        {
          return date [2 + m-1];
        }
        else if (yearzie == 2 || yearzie == 7)
        {
          return date [14 + m-1];
        }
        else if (yearzie == 3 || yearzie == 8)
        {
          return date [26 + m-1];
        }
        else if (yearzi == 4 || yearzi == 9)
        {
          return date [38 + m-1];
        }
        else if (yearzie == 5 || yearzie == 10)
        {
          return date [50 + m-1>60?(m-11):49 + m];
        }
      }
      return date [1];
    }
    public string dayei (int year, int day) {
      int yearzie=yearnum (year);
      return date [(yearzie + day)%60-1];
    }
    public string hours (int hour, int day, int year) {
      int yearzie=yearnum (year);
      string strh="";
      int datey=(yearzie + day)%60-1;
      int datezi=datey%10;
      if (datezi == 1 || datezi == 5)
      {
        strh +="A";
      }
      else if (datezi == 2 || datezi == 6)
      {
        strh +="C";
      }
      else if (datezi == 3 || datezi == 7)
      {
        strh +="pent";
      }
      else if (datezi == 4 || datezi == 8)
      {
        strh +="ung";
      }
      else if (datezi == 5 || datezi == 0)
      {
        strh +="ren";
      }
      if (hour>0&&hour<= 1)
      {
         strh +="child";
      }
      else if (hour>1&&hour<= 3)
      {
        strh +="ugly";
      }
      else if (hour>3&&hour<= 5)
      {
        strh +="yin";
      }
      else if (hour>5&&hour<= 7)
      {
        strh +="D";
      }
      else if (hour>7&&hour<= 9)
      {
        strh +="chen";
      }
      else if (hour>9&&hour<= 11)
      {
        strh +="Pat";
      }
      else if (hour>11&&hour<= 13)
      {
        strh +="afternoon";
      }
      else if (hour>13&&hour<15)
      {
        strh +="not";
      }
      else if (hour>15&&hour<17)
      {
        strh +="Apply";
      }
      else if (hour>17&&hour<19)
      {
        strh +="child";
      }
      else if (hour>19&&hour<= 21)
      {
        strh +="unitary";
      }
      else if (hour>21&&hour<= 23)
      {
        strh +="pent";
      }
      else if (hour>0&&hour<1)
      {
        strh +="sea";
      }
      return strh;
    }
    public int yearnum (int year) {
      int yearzie=year%60-3;
      if (yearzie<= 0)
      {
        yearzie +=60;
      }
      return yearzie;
    }
  }
}
c
  • Previous C # code for generating random numbers
  • Next Detailed explanation of default parameters in Javascript