zoukankan      html  css  js  c++  java
  • 使用ChineseLunisolarCalendar 对象由年份获得生肖名,Datetime.now.tostring获得星期几

    一:使用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
            }
        }
    }
  • 相关阅读:
    可横向滑动的vue tab组件
    css超出不换行可滑动
    js 背景从无到黑的渐变 字从白到黑的渐变
    js给文本添加行号
    前端兼容性问题
    jq操作table追加td
    js定时器
    js 时间戳 中国标准时间 年月日 日期之间的转换
    Swift教程之函数
    Swift教程之控制流
  • 原文地址:https://www.cnblogs.com/hongmaju/p/3763452.html
Copyright © 2011-2022 走看看