php计算八字的算法,C#编写的生辰八字计算程序
作者故意删除了注释,读不懂代码的,就加作者QQ721159175咨询吧,作者很乐意与你分享并解答~
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//假设一个人的公历出生时间,范围必须要在2012-2015年之间,因为本示例程序只提供了这几年的农历数据
//修改这几个赋值,运行程序,可以得到生辰八字
GuaZhu.nQiGuaYear = 2015;//年
GuaZhu.nQiGuaMonth = 2;//月
GuaZhu.nQiGuaDay = 6;//日
GuaZhu.nQiGuaHour = 23;//时
GuaZhu.nQiGuaMinute = 33;//分
GuaZhu.GetSiZhu();
}
}
public static class GuaZhu
{
public static int nQiGuaYear;
public static int nQiGuaMonth;
public static int nQiGuaDay;
public static int nQiGuaHour;
public static int nQiGuaMinute;
public static int JieQiMonth;
public static string PrevJQYear;
public static string PrevJQMonth;
public static string PrevJQDay;
public static string PrevJQHour;
public static string PrevJQMinute;
public static string NextJQYear;
public static string NextJQMonth;
public static string NextJQDay;
public static string NextJQHour;
public static string NextJQMinute;
public static string sSiZhu;
public static string nTianGan;
public static string yTianGan;
public static string rTianGan;
public static string sTianGan;
public static string nDiZhi;
public static string yDiZhi;
public static string rDiZhi;
public static string sDiZhi;
public static int nTianGanID;
public static int yTianGanID;
public static int rTianGanID;
public static string PrevJieQi;
public static string NextJieQi;
public static string[] TianGan = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
public static string[] DiZhi = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
public static string[] JieQi = {
"1/6/2012 06:44","2/4/2012 18:22","3/5/2012 12:21","4/4/2012 17:06","5/5/2012 10:20","6/5/2012 14:26","7/7/2012 00:41",
"8/7/2012 10:31","9/7/2012 13:29","10/8/2012 05:12","11/7/2012 08:26","12/7/2012 01:19","1/5/2013 12:34","2/4/2013 00:13",
"3/5/2013 18:15","4/4/2013 23:02","5/5/2013 16:18","6/5/2013 20:23","7/7/2013 06:35","8/7/2013 16:20","9/7/2013 19:16",
"10/8/2013 10:58","11/7/2013 14:14","12/7/2013 07:09","1/5/2014 18:24","2/4/2014 06:03","3/6/2014 00:02","4/5/2014 04:47",
"5/5/2014 21:59","6/6/2014 02:03","7/7/2014 12:15","8/7/2014 22:03","9/8/2014 01:01","10/8/2014 16:48","11/7/2014 20:07",
"12/7/2014 13:04","1/6/2015 00:20","2/4/2015 11:58","3/6/2015 05:55","4/5/2015 10:39","5/6/2015 03:52","6/6/2015 07:58",
"7/7/2015 18:12","8/6/2015 04:01","9/8/2015 06:59","10/8/2015 22:43","11/8/2015 01:58","12/7/2015 18:53",
};
public static void GetnGanZhi()
{
int year, year1, year2;
year = GuaZhu.nQiGuaYear;
if (GuaZhu.nQiGuaMonth == 1)
{
year -= 1;
}
else if (GuaZhu.nQiGuaMonth == 2)
{
DateTime lichun, birthday1;
lichun = DateTime.Parse("2012-2-4 18:22");
string birthday2;
switch (GuaZhu.nQiGuaYear - 2012)
{
case 0:
lichun = DateTime.Parse("2012-2-4 18:22");
break;
case 1:
lichun = DateTime.Parse("2013-2-4 00:13");
break;
case 2:
lichun = DateTime.Parse("2014-2-4 06:03");
break;
case 3:
lichun = DateTime.Parse("2015-2-4 11:58");
break;
}
birthday2 = GuaZhu.nQiGuaYear + "-" + GuaZhu.nQiGuaMonth + "-" + GuaZhu.nQiGuaDay + " " + GuaZhu.nQiGuaHour + ":" + GuaZhu.nQiGuaMinute;
birthday1 = DateTime.Parse(birthday2);
if (birthday1 < lichun)
{
year -= 1;
}
}
year1 = year % 10 < 4 ? (year % 10 + 10) : year % 10;
year2 = year % 12 < 4 ? (year % 12 + 12) : year % 12;
nTianGan = TianGan[year1 - 4];
nDiZhi = DiZhi[year2 - 4];
}
public static void GetYueGan()
{
yTianGanID = nTianGanID * 2 + JieQiMonth + 1;
if ((yTianGanID >= 10) && (yTianGanID < 20))
{
yTianGanID -= 10;
}
else if (yTianGanID >= 20)
{
yTianGanID -= 20;
}
if (yTianGanID == 10)
{
yTianGanID = 0;
}
yTianGan = TianGan[yTianGanID];
}
public static void GetyGanZhi()
{
string sJieQiName1 = "", sJieQiName2 = "";
string birthday2;
birthday2 = GuaZhu.nQiGuaYear + "-" + GuaZhu.nQiGuaMonth + "-" + GuaZhu.nQiGuaDay + " " + GuaZhu.nQiGuaHour + ":" + GuaZhu.nQiGuaMinute;
DateTime date = DateTime.Parse(birthday2);
for (int i = 46; i > -1; i--)
{
if ((i + 1) % 12 > 8)
{
PrevJQYear = JieQi[i + 1].Substring(5, 4);
PrevJQMonth = JieQi[i + 1].Substring(0, 2);
PrevJQDay = JieQi[i + 1].Substring(3, 1);
}
else
{
PrevJQYear = JieQi[i + 1].Substring(4, 4);
PrevJQMonth = JieQi[i + 1].Substring(0, 1);
PrevJQDay = JieQi[i + 1].Substring(2, 1);
}
PrevJQHour = JieQi[i + 1].Substring(JieQi[i + 1].Length - 5, 2);
PrevJQMinute = JieQi[i + 1].Substring(JieQi[i + 1].Length - 2, 2);
PrevJieQi = PrevJQYear + "-" + PrevJQMonth + "-" + PrevJQDay + " " + PrevJQHour + ":" + PrevJQMinute;
if (i % 12 > 8)
{
NextJQYear = JieQi[i].Substring(5, 4);
NextJQMonth = JieQi[i].Substring(0, 2);
NextJQDay = JieQi[i].Substring(3, 1);
}
else
{
NextJQYear = JieQi[i].Substring(4, 4);
NextJQMonth = JieQi[i].Substring(0, 1);
NextJQDay = JieQi[i].Substring(2, 1);
}
NextJQHour = JieQi[i].Substring(JieQi[i].Length - 5, 2);
NextJQMinute = JieQi[i].Substring(JieQi[i].Length - 2, 2);
NextJieQi = NextJQYear + "-" + NextJQMonth + "-" + NextJQDay + " " + NextJQHour + ":" + NextJQMinute;
DateTime date2 = DateTime.Parse(NextJieQi);
if (date >= date2)
{
switch (i % 12)
{
case 1:
sJieQiName1 = "立春:";
sJieQiName2 = "惊蛰:";
JieQiMonth = 1;
break;
case 2:
sJieQiName1 = "惊蛰:";
sJieQiName2 = "清明:";
JieQiMonth = 2;
break;
case 3:
sJieQiName1 = "清明:";
sJieQiName2 = "立夏:";
JieQiMonth = 3;
break;
case 4:
sJieQiName1 = "立夏:";
sJieQiName2 = "芒种:";
JieQiMonth = 4;
break;
case 5:
sJieQiName1 = "芒种:";
sJieQiName2 = "小暑:";
JieQiMonth = 5;
break;
case 6:
sJieQiName1 = "小暑:";
sJieQiName2 = "立秋:";
JieQiMonth = 6;
break;
case 7:
sJieQiName1 = "立秋:";
sJieQiName2 = "白露:";
JieQiMonth = 7;
break;
case 8:
sJieQiName1 = "白露:";
sJieQiName2 = "寒露:";
JieQiMonth = 8;
break;
case 9:
sJieQiName1 = "寒露:";
sJieQiName2 = "立冬:";
JieQiMonth = 9;
break;
case 10:
sJieQiName1 = "立冬:";
sJieQiName2 = "大雪:";
JieQiMonth = 10;
break;
case 11:
sJieQiName1 = "大雪:";
sJieQiName2 = "小寒:";
JieQiMonth = 11;
break;
case 0:
sJieQiName1 = "小寒:";
sJieQiName2 = "立春:";
JieQiMonth = 12;
break;
}
PrevJieQi = sJieQiName2 + PrevJQYear + "年" + PrevJQMonth + "月" + PrevJQDay + "日" + PrevJQHour + "时" + PrevJQMinute + "分";
NextJieQi = sJieQiName1 + NextJQYear + "年" + NextJQMonth + "月" + NextJQDay + "日" + NextJQHour + "时" + NextJQMinute + "分";
break;
}
}
switch (nTianGan)
{
case "甲":
nTianGanID = 0;
GetYueGan();
break;
case "乙":
nTianGanID = 1;
GetYueGan();
break;
case "丙":
nTianGanID = 2;
GetYueGan();
break;
case "丁":
nTianGanID = 3;
GetYueGan();
break;
case "戊":
nTianGanID = 4;
GetYueGan();
break;
case "己":
nTianGanID = 5;
GetYueGan();
break;
case "庚":
nTianGanID = 6;
GetYueGan();
break;
case "辛":
nTianGanID = 7;
GetYueGan();
break;
case "壬":
nTianGanID = 8;
GetYueGan();
break;
case "癸":
nTianGanID = 9;
GetYueGan();
break;
}
if (JieQiMonth <= 10)
{
yDiZhi = DiZhi[JieQiMonth + 1];
}
else if (JieQiMonth == 11)
{
JieQiMonth = 0;
yDiZhi = DiZhi[JieQiMonth];
}
else
{
JieQiMonth = 1;
yDiZhi = DiZhi[JieQiMonth];
}
}
public static void GetrGanZhi()
{
DateTime baseDate = new DateTime(2000, 1, 1);
DateTime qiguaDate = new DateTime(GuaZhu.nQiGuaYear, GuaZhu.nQiGuaMonth, GuaZhu.nQiGuaDay);
TimeSpan ts = qiguaDate - baseDate;
int gapdays = ts.Days;
if (GuaZhu.nQiGuaHour == 23)
{
gapdays += 1;
}
if (gapdays >= 6)
{
rTianGan = TianGan[(gapdays - 6) % 10];
rDiZhi = DiZhi[(gapdays - 6) % 12];
}
else if (gapdays < 0)
{
gapdays = gapdays * (-1);
rTianGan = TianGan[(gapdays + 6) % 10];
rDiZhi = DiZhi[(gapdays + 6) % 12];
}
else
{
switch (gapdays)
{
case 0:
rTianGan = "戊";
rDiZhi = "午";
break;
case 1:
rTianGan = "己";
rDiZhi = "未";
break;
case 2:
rTianGan = "庚";
rDiZhi = "申";
break;
case 3:
rTianGan = "辛";
rDiZhi = "酉";
break;
case 4:
rTianGan = "壬";
rDiZhi = "戌";
break;
case 5:
rTianGan = "癸";
rDiZhi = "亥";
break;
}
}
}
public static void GetShiGan()
{
if (GuaZhu.nQiGuaHour == 23 || GuaZhu.nQiGuaHour == 0)
{
rTianGanID = 0 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 1 || GuaZhu.nQiGuaHour == 2)
{
rTianGanID = 1 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 3 || GuaZhu.nQiGuaHour == 4)
{
rTianGanID = 2 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 5 || GuaZhu.nQiGuaHour == 6)
{
rTianGanID = 3 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 7 || GuaZhu.nQiGuaHour == 8)
{
rTianGanID = 4 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 9 || GuaZhu.nQiGuaHour == 10)
{
rTianGanID = 5 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 11 || GuaZhu.nQiGuaHour == 12)
{
rTianGanID = 6 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 13 || GuaZhu.nQiGuaHour == 14)
{
rTianGanID = 7 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 15 || GuaZhu.nQiGuaHour == 16)
{
rTianGanID = 8 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 17 || GuaZhu.nQiGuaHour == 18)
{
rTianGanID = 9 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 19 || GuaZhu.nQiGuaHour == 20)
{
rTianGanID = 10 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
else if (GuaZhu.nQiGuaHour == 21 || GuaZhu.nQiGuaHour == 22)
{
rTianGanID = 11 + rTianGanID;
rTianGanID = rTianGanID > 9 ? (rTianGanID - 10) : rTianGanID;
sTianGan = TianGan[rTianGanID];
}
}
public static void GetsGanZhi()
{
if (rTianGan == "甲" || rTianGan == "己")
{
rTianGanID = 0;
GetShiGan();
}
else if (rTianGan == "乙" || rTianGan == "庚")
{
rTianGanID = 2;
GetShiGan();
}
else if (rTianGan == "丙" || rTianGan == "辛")
{
rTianGanID = 4;
GetShiGan();
}
else if (rTianGan == "丁" || rTianGan == "壬")
{
rTianGanID = 6;
GetShiGan();
}
else
{
rTianGanID = 8;
GetShiGan();
}
if (GuaZhu.nQiGuaHour == 23 || GuaZhu.nQiGuaHour == 0)
{
sDiZhi = DiZhi[0];
}
if (GuaZhu.nQiGuaHour == 1 || GuaZhu.nQiGuaHour == 2)
{
sDiZhi = DiZhi[1];
}
if (GuaZhu.nQiGuaHour == 3 || GuaZhu.nQiGuaHour == 4)
{
sDiZhi = DiZhi[2];
}
if (GuaZhu.nQiGuaHour == 5 || GuaZhu.nQiGuaHour == 6)
{
sDiZhi = DiZhi[3];
}
if (GuaZhu.nQiGuaHour == 7 || GuaZhu.nQiGuaHour == 8)
{
sDiZhi = DiZhi[4];
}
if (GuaZhu.nQiGuaHour == 9 || GuaZhu.nQiGuaHour == 10)
{
sDiZhi = DiZhi[5];
}
if (GuaZhu.nQiGuaHour == 11 || GuaZhu.nQiGuaHour == 12)
{
sDiZhi = DiZhi[6];
}
if (GuaZhu.nQiGuaHour == 13 || GuaZhu.nQiGuaHour == 14)
{
sDiZhi = DiZhi[7];
}
if (GuaZhu.nQiGuaHour == 15 || GuaZhu.nQiGuaHour == 16)
{
sDiZhi = DiZhi[8];
}
if (GuaZhu.nQiGuaHour == 17 || GuaZhu.nQiGuaHour == 18)
{
sDiZhi = DiZhi[9];
}
if (GuaZhu.nQiGuaHour == 19 || GuaZhu.nQiGuaHour == 20)
{
sDiZhi = DiZhi[10];
}
if (GuaZhu.nQiGuaHour == 21 || GuaZhu.nQiGuaHour == 22)
{
sDiZhi = DiZhi[11];
}
}
public static void GetSiZhu()
{
GetnGanZhi();
GetyGanZhi();
GetrGanZhi();
GetsGanZhi();
sSiZhu = nTianGan + nDiZhi + " " + yTianGan + yDiZhi + " ";
sSiZhu += rTianGan + rDiZhi + " " + sTianGan + sDiZhi;
string birthday;
birthday = nQiGuaYear + "年" + nQiGuaMonth + "月" + nQiGuaDay + "日" + nQiGuaHour + "时" + nQiGuaMinute + "分";
Console.WriteLine("公历出生时间:" + birthday);
Console.WriteLine("前一节气是" + NextJieQi);
Console.WriteLine("后一节气是" + PrevJieQi);
Console.WriteLine("命主生辰八字是:" + sSiZhu);
Console.WriteLine("请按任意键继续...");
Console.ReadKey();
}
}
}
以上就是本文给大家分享的代码的全部内容了,希望大家能够喜欢,能够对大家学习C#有所帮助。
php计算八字的算法,C#编写的生辰八字计算程序相关推荐
- 设计计算机程序时 要考虑计算的过程,算法和程序设计练习题
<算法和程序设计练习题>由会员分享,可在线阅读,更多相关<算法和程序设计练习题(10页珍藏版)>请在技术文库上搜索. 1.算法和程序设计练习题一.选择题:1.使用计算机解题的步 ...
- 量子计算机 漫画,漫画 | 10分钟看懂量子比特、量子计算和量子算法
原标题:漫画 | 10分钟看懂量子比特.量子计算和量子算法 请做好准备,即将进入烧脑模式! 宏观世界的生活经验很多都是表象.比如,你可能认为世界的运行是确定的.可预测的:一个物体不可能同时处于两个相互 ...
- R语言使用caret包的confusionMatrix函数计算混淆矩阵、使用编写的自定义函数可视化混淆矩阵(confusion matrix)
R语言使用caret包的confusionMatrix函数计算混淆矩阵.使用编写的自定义函数可视化混淆矩阵(confusion matrix) 目录
- ARCore中根据屏幕坐标计算射线的算法
ARCore中根据屏幕坐标计算射线的算法 ARCore中提供了根据屏幕坐标.视口大小及view. project矩阵计算从屏幕坐标发射一条射线的方法,此方法用于3D拾取. 1 class Ray { ...
- Java黑皮书课后题第3章:**3.19(计算三角形的周长)编写程序,读取三角形的三个边,如果输入值合法就计算这个三角形的周长;否则,显示这些输入值不合法。如果任意两条边的和大于第三边,则输入值都是合
**3.18(计算三角形的周长)编写程序,读取三角形的三个边,如果输入值合法就计算这个三角形的周长:否则,显示这些输入值不合法.如果任意两条边的和大于第三边,则输入值都是合法的 题目 题目概述 破题 ...
- 相似度计算 java_Java基于余弦方法实现的计算相似度算法示例
Java基于余弦方法实现的计算相似度算法示例 引导语:Java 编程语言的风格十分接近C.C++语言.Java是一个纯的面向对象的程序设计语言,以下是小编整理的Java基于余弦方法实现的`计算相似度算 ...
- C#:实现麦克劳林级数计算非线性函数算法(附完整源码)
C#:实现麦克劳林级数计算非线性函数算法 using System; using System.Linq;namespace Algorithms.Numeric.Series {public sta ...
- 没有计算的推理和基于推理的计算 逻辑与算法之五
没有计算的推理和基于推理的计算 逻辑与算法之五 近现代科学的创立和发展,按照爱因斯坦的说法,一个是古希腊人为科学准备的理论体系,一个是文艺复兴时期开创的实验方法,用系统实验来寻求自然现象之间的因果联系 ...
- java计算年龄_java根据出生年月日精确计算年龄的算法
今天项目中有个根据出生年月日,需要精确计算年龄的算法,找了半天才算有个正确的,分享出来给牛牛们成为自己java代码库的一部分算法.public static int getAge(Date dateO ...
最新文章
- 【目标检测】yolo系列:从yolov1到yolov5之YOLOv1详解及复现
- 大规模环境下基于语义直方图的多机器人实时全局定位图匹配
- 真,数学之美!用数学方式打开Facebook新Logo!旋转变换?
- 数据库学习day_03:关联关系/ 关联查询/ JDBC
- HoughLinesP函数(概率检测直线)
- 一文讲透非标品的商品类目设计
- C#中 paint()与Onpaint()的区别
- c语言fgets函数的用法
- java中静态代码块的用法 static用法详解
- (39)FPGA四种常用逻辑门(与非门)
- 左耳朵耗子:你得知道,技术不是用来写 CRUD 的
- 特殊符号 mysql_mysql 特殊字符
- 【Android驱动】屏和TP谁先休眠的问题
- 疫情期间,程序员是如何靠副业赚钱的?​
- 初识p-code (pcode)
- 计算机领域十大世界难题,最强思维碰撞:世界十大逻辑难题
- 新电脑从另外一台电脑完整拷贝环境,不需要安装环境
- uvm学习笔记----适合新手快速学习
- Postman安装与基本操作
- 计算机公办学校招收人数,2018长沙市小升初微机派位一共有多少人参加
热门文章
- 12.看板方法——度量和管理报告笔记
- 精品德国软件 UltraShredder 文件粉碎机
- 什么工具压缩视频文件好用
- uniapp 视频压缩插件 Ba-VideoCompressor
- java ftp上传文件相关代码梳理
- 中国芯片封测行业规划研究及发展前景投资可行性分析报告2022-2028年版
- 基于LaTeX-OCR公式转换工具的安装与使用
- java写脸萌_Linux环境下配置JDK,java环境
- correction of probe pressure artifacts in freehand 3D ultrasound
- C#开源: 全局钩子+正则表达式=后台自动获取扫描枪数据