日期:2014-06-10  浏览次数:20364 次

一:使用ChineseLunisolarCalendar 对象由年份获得生肖名,截图

二:代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GetShengXiao
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        private void btn_Get_Click(object sender, EventArgs e)
        {
            System.Globalization.ChineseLunisolarCalendar chinseCaleander =//创建日历对象ChineseLunisolarCalendar,将时间分成多个部分来表示,如分成年、月和日。 年按农历计算,而日和月按阴阳历计算。
                 new System.Globalization.ChineseLunisolarCalendar();
            string TreeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";//创建字符串对象
            int intYear = chinseCaleander.GetSexagenaryYear(DateTime.Now);//计算年信息,GetSexagenaryYear计算与指定日期对应的甲子(60 年)循环中的年。
            string Tree = TreeYear.Substring(chinseCaleander.//得到生肖信息
                GetTerrestrialBranch(intYear) - 1, 1);//GetTerrestrialBranch计算甲子(60 年)循环中指定年份的地支,
            //Substring(x,y)从此实例检索子字符串。 子字符串从指定的字符位置开始且具有指定的长度
            MessageBox.Show("今年是十二生肖" + Tree + "",//输出生肖信息
                "判断十二生肖", MessageBoxButtons.OK,
                MessageBoxIcon.Information);
        }
    }
}

 三:now.tostring获得星期几,截图

四:代码

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 GetWeek
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        private void btn_GetWeek_Click(object sender, EventArgs e)
        {
            MessageBox.Show("今天是: "//显示星期信息
                + DateTime.Now.ToString("dddd"), "提示!");//dddd是星期日,ddd是日,dd是01
        }
    }
}