C#项目获取当前时间的农历时间
https://blog.csdn.net/cstester/article/details/7407044
- using System.Globalization;
- class CnCanlendar_nongli
- {
- /// <summary>
- /// 实例化一个 ChineseLunisolarCalendar
- /// </summary>
- private static ChineseLunisolarCalendar ChineseCalendar = new ChineseLunisolarCalendar();
- /// <summary>
- /// 十天干
- /// </summary>
- private static string[] tg = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
- /// <summary>
- /// 十二地支
- /// </summary>
- private static string[] dz = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
- /// <summary>
- /// 十二生肖
- /// </summary>
- private static string[] sx = { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
- /// <summary>
- /// 返回农历天干地支年
- /// </summary>
- /// <param name="year">农历年</param>
- /// <returns></returns>
- public static string GetLunisolarYear(int year)
- {
- if (year > 3)
- {
- int tgIndex = (year - 4) % 10;
- int dzIndex = (year - 4) % 12;
- return string.Concat(tg[tgIndex], dz[dzIndex], "[", sx[dzIndex], "]");
- }
- throw new ArgumentOutOfRangeException("无效的年份!");
- }
- /// <summary>
- /// 农历月
- /// </summary>
- /// <returns></returns>
- private static string[] months = { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)" };
- /// <summary>
- /// 农历日
- /// </summary>
- private static string[] days1 = { "初", "十", "廿", "三" };
- /// <summary>
- /// 农历日
- /// </summary>
- private static string[] days = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
- /// <summary>
- /// 返回农历月
- /// </summary>
- /// <param name="month">月份</param>
- /// <returns></returns>
- public static string GetLunisolarMonth(int month)
- {
- if (month < 13 && month > 0)
- {
- return months[month - 1];
- }
- throw new ArgumentOutOfRangeException("无效的月份!");
- }
- /// <summary>
- /// 返回农历日
- /// </summary>
- /// <param name="day">天</param>
- /// <returns></returns>
- public static string GetLunisolarDay(int day)
- {
- if (day > 0 && day < 32)
- {
- if (day != 20 && day != 30)
- {
- return string.Concat(days1[(day - 1) / 10], days[(day - 1) % 10]);
- }
- else
- {
- return string.Concat(days[(day - 1) / 10], days1[1]);
- }
- }
- throw new ArgumentOutOfRangeException("无效的日!");
- }
- /// <summary>
- /// 根据公历获取农历日期
- /// </summary>
- /// <param name="datetime">公历日期</param>
- /// <returns></returns>
- public static string GetChineseDateTime(DateTime datetime)
- {
- //农历的年月日
- int year = ChineseCalendar.GetYear(datetime);
- int month = ChineseCalendar.GetMonth(datetime);
- int day = ChineseCalendar.GetDayOfMonth(datetime);
- //获取闰月, 0 则表示没有闰月
- int leapMonth = ChineseCalendar.GetLeapMonth(year);
- bool isleap = false;
- if (leapMonth > 0)
- {
- if (leapMonth == month)
- {
- //闰月
- isleap = true;
- month--;
- }
- else if (month > leapMonth)
- {
- month--;
- }
- }
- return string.Concat(GetLunisolarYear(year), "年", isleap ? "闰" : string.Empty, GetLunisolarMonth(month), "月", GetLunisolarDay(day));
- }
- }
C#项目获取当前时间的农历时间的更多相关文章
- 代码空间项目 -- 获取当前时间之前的某一天-Calender类的使用
Calendar类的静态方法getInstance()可以初始化一个日历对象:Calendar now = Calendar.getInstance(); 1.Calendar的基本用法calenda ...
- js获取当前农历时间
<template> <div class="gaia-header"> <img alt="gaia_logo" src=&qu ...
- ASP.NET农历时间显示(两)
在拍摄的月球时前(http://blog.csdn.net/yysyangyangyangshan/article/details/6802950),只是没有进行封装使用起来须要手动改动. 本次进行简 ...
- ASP.NET如何显示农历时间
ASP.NET如何显示农历时间 CS部分代码如下: 代码如下: public string ChineseTimeNow = ""; public string ForignTi ...
- 项目心得——按照指定的日期/时间创建Date对象
项目心得——按照指定的日期/时间创建Date对象 有时,在做项目中,需要获得指定日期的Date对象,这个指定的日期或者时间可能不是当前的时间.下面讲解两种获取指定日期/时间的Date对象的方法: pa ...
- Java 获取当前时间及实现时间倒计时功能
引言 在一些项目中或是一些特殊的业务场景中,需要用到显示系统的当前时间,以及一些固定的时间倒计时,时间到后做一些什么事情的业务 .接下来咱们就具体看看代码是怎么实现的: <%@ page lan ...
- 用PHP获取系统时间时,时间比当前时间少8个小时
自PHP5.0开始,用PHP获取系统时间时,时间比当前时间少8个小时.原因是PHP.ini中没有设置timezone时,PHP是使用的UTC时间,所以在中国时间要少8小时. 解决办法: 1.在PHP. ...
- [WinAPI] API 14 [获取、设置文件属性和时间]
>_< 为了获取文件属性,用户可以使用GetFileAttributes与GetFileAttributesEx函数. GetFileAttributesEx函数除了返回文件属性外,还返回 ...
- Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数
格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...
随机推荐
- Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置
用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...
- Java多线程之定时任务(Timer)
package org.study2.javabase.ThreadsDemo.schedule; import java.util.Date; import java.util.Timer; imp ...
- Java反射和注解
反射:http://blog.csdn.net/liujiahan629629/article/details/18013523 注解:http://www.cnblogs.com/peida/arc ...
- MobX基础 ----- 类的静态属性和装饰器
当我们使用MobX的时候,首先要声明一个store, 用来保存状态,它的最基本的语法 如下: class Todo { @observable title = ""; @obser ...
- moogodb 安装及简单介绍
1,安装Moogodb 因为是windows 64位操作系统,直接到官网上下载.msi文件,下载完成后点击安装,点击同意协议之后,出现下面的对话框, Choose Setup Type, 就是选择安装 ...
- codeforces703B
Mishka and trip CodeForces - 703B 小米什卡是一个伟大的旅行者,她访问了许多国家.在这次考虑去哪里旅行之后,她选择了XXX--这个美丽,但鲜为人知的北方国家. 以下是关 ...
- kubernetes 基本命令
查询命令: kubectl get pods -n kube-system kubectl get ClusterRole -n kube-system kubectl get ClusterRole ...
- Luogu5205 【模板】多项式开根(NTT+多项式求逆)
https://www.cnblogs.com/HocRiser/p/8207295.html 安利! 写NTT把i<<=1写成了i<<=2,又调了一年.发现我的日常就是数组开 ...
- python3,打印一年的某一天是一年的第几天
year = int(input('year:')) month = int(input('month:')) day = int(input('day:')) months = (0,31,59,9 ...
- 【BZOJ4872】【SHOI2017】分手是祝愿 期望DP
题目大意 有\(n\)盏灯和\(n\)个开关,初始时有的灯是亮的,有的灯是暗的.按下第\(i\)个开关会使第\(j\)盏灯的状态被改变,其中\(j|i\).每次你会随机操作一个开关,直到可以通过不多于 ...