C# 中 怎样获得当前星期以及农历时间

C# 中 怎样获得当前星期以及农历时间,第1张

这是网上的例子,你仔细看看

using System;

using SystemData;

using SystemConfiguration;

using SystemWeb;

using SystemWebSecurity;

using SystemWebUI;

using SystemWebUIWebControls;

using SystemWebUIWebControlsWebParts;

using SystemWebUIHtmlControls;

using System;

using SystemCollectionsGeneric;

using SystemText;

using SystemGlobalization;

/// <summary>

/// chinaDate 的摘要说明

/// </summary>

public class chinaDate

{

public string cDate()

{

ChineseLunisolarCalendar l = new ChineseLunisolarCalendar();

DateTime dt = DateTimeToday; //转换当日的日期

//dt = new DateTime(2006, 1,29);//农历2006年大年初一(测试用),也可指定日期转换

string[] aMonth ={"","正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "腊月", "腊月" };

//a10表示日期的十位!

string[] a10 ={ "初", "十", "廿", "卅" };

string[] aDigi ={ "O", "一", "二", "三", "四", "五", "六", "七", "八", "九" };

string sYear = "", sYearArab = "", sMonth = "", sDay = "", sDay10 = "", sDay1 = "", sLuniSolarDate = "";

int iYear, iMonth, iDay;

iYear = lGetYear(dt);

iMonth = lGetMonth(dt);

iDay = lGetDayOfMonth(dt);

//Format Year

sYearArab = iYearToString();

for (int i = 0; i < sYearArabLength; i++)

{

sYear += aDigi[ConvertToInt16(sYearArabSubstring(i, 1))];

}

//Format Month

int iLeapMonth = lGetLeapMonth(iYear); //获取闰月

if (iLeapMonth > 0 && iMonth<=iLeapMonth)

{

//for (int i = iLeapMonth + 1; i < 13; i++) aMonth[i] = aMonth[i - 1];

aMonth[iLeapMonth] = "闰" + aMonth[iLeapMonth-1];

sMonth = aMonth[lGetMonth(dt)];

}

else if (iLeapMonth > 0 && iMonth > iLeapMonth)

{

sMonth = aMonth[lGetMonth(dt) - 1];

}

else

{

sMonth = aMonth[lGetMonth(dt)];

}

//Format Day

sDay10 = a10[iDay / 10];

sDay1 = aDigi[(iDay % 10)];

sDay = sDay10 + sDay1;

if (iDay == 10) sDay = "初十";

if (iDay == 20) sDay = "二十";

if (iDay == 30) sDay = "三十";

//Format Lunar Date

//sLuniSolarDate = dtYear+"年"+dtMonth+"月"+dtDay+"日 "+Weeks(dtDayOfWeekToString())+" 农历" + sYear + "年" + sMonth + sDay;

sLuniSolarDate =" 农历" + sMonth + sDay;

return sLuniSolarDate;

}

private string Weeks(string Weeken)

{

switch (Weeken)

{

case "Monday":

return "星期一";

break;

case "Tuesday":

return "星期二";

break;

case "Wednesday":

return "星期三";

break;

case "Thursday":

return "星期四";

break;

case "Friday":

return "星期五";

break;

case "Saturday":

return "星期六";

break;

case "Sunday":

return "星期日";

break;

default:

return " ";

}

}

}

二、第二步

chinaDate s = new chinaDate();

Label1Text = DateTimeNowToShortDateString() + " " + CaculateWeekDay(DateTimeNowDayOfWeekToString()) + " " + scDate();

三、第三步

#region 得到今天是星期几

protected string CaculateWeekDay(string week)

{

string weekstr = "";

switch (week)

{

case "Monday": weekstr = "星期一"; break;

case "Tuesday": weekstr = "星期二"; break;

case "Wednesday": weekstr = "星期三"; break;

case "Thursday": weekstr = "星期四"; break;

case "Friday": weekstr = "星期五"; break;

case "Saturday": weekstr = "星期六"; break;

case "Sunday": weekstr = "星期日"; break;

}

return weekstr;

}

#endregion

string time = Calendar1SelectedDateDayOfWeekToString();

string time = DateTimeNowDayOfWeekToString();

不过选出来的是英文的

这个连农历者能显示。代码:<SCRIPT language=JavaScript>

<!--

var bsYear;

var bsDate;

var bsWeek;

var arrLen=8; //数组长度

var sValue=0; //当年的秒数

var dayiy=0; //当年第几天

var miy=0; //月份的下标

var iyear=0; //年份标记

var dayim=0; //当月第几天

var spd=86400; //每天的秒数

var year1999="30;29;29;30;29;29;30;29;30;30;30;29"; //354

var year2000="30;30;29;29;30;29;29;30;29;30;30;29"; //354

var year2001="30;30;29;30;29;30;29;29;30;29;30;29;30"; //384

var year2002="30;30;29;30;29;30;29;29;30;29;30;29"; //354

var year2003="30;30;29;30;30;29;30;29;29;30;29;30"; //355

var year2004="29;30;29;30;30;29;30;29;30;29;30;29;30"; //384

var year2005="29;30;29;30;29;30;30;29;30;29;30;29"; //354

var year2006="30;29;30;29;30;30;29;29;30;30;29;29;30";

var month1999="正月;二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月"

var month2001="正月;二月;三月;四月;闰四月;五月;六月;七月;八月;九月;十月;十一月;十二月"

var month2004="正月;二月;闰二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月"

var month2006="正月;二月;三月;四月;五月;六月;七月;闰七月;八月;九月;十月;十一月;十二月"

var Dn="初一;初二;初三;初四;初五;初六;初七;初八;初九;初十;十一;十二;十三;十四;十五;十六;十七;十八;十九;二十;廿一;廿二;廿三;廿四;廿五;廿六;廿七;廿八;廿九;三十";

var Ys=new Array(arrLen);

Ys[0]=919094400;Ys[1]=949680000;Ys[2]=980265600;

Ys[3]=1013443200;Ys[4]=1044028800;Ys[5]=1074700800;

Ys[6]=1107878400;Ys[7]=1138464000;

var Yn=new Array(arrLen); //农历年的名称

Yn[0]="己卯年";Yn[1]="庚辰年";Yn[2]="辛巳年";

Yn[3]="壬午年";Yn[4]="癸未年";Yn[5]="甲申年";

Yn[6]="乙酉年";Yn[7]="丙戌年";

var D=new Date();

var yy=DgetYear();

var mm=DgetMonth()+1;

var dd=DgetDate();

var ww=DgetDay();

if (ww==0) ww="<font color=RED>星期日";

if (ww==1) ww="星期一";

if (ww==2) ww="星期二";

if (ww==3) ww="星期三";

if (ww==4) ww="星期四";

if (ww==5) ww="星期五";

if (ww==6) ww="<font color=RED>星期六";

ww=ww;

var ss=parseInt(DgetTime() / 1000);

if (yy<100) yy="19"+yy;

for (i=0;i<arrLen;i++)

if (ss>=Ys[i]){

iyear=i;

sValue=ss-Ys[i]; //当年的秒数

}

dayiy=parseInt(sValue/spd)+1; //当年的天数

var dpm=year1999;

if (iyear==1) dpm=year2000;

if (iyear==2) dpm=year2001;

if (iyear==3) dpm=year2002;

if (iyear==4) dpm=year2003;

if (iyear==5) dpm=year2004;

if (iyear==6) dpm=year2005;

if (iyear==7) dpm=year2006;

dpm=dpmsplit(";");

var Mn=month1999;

if (iyear==2) Mn=month2001;

if (iyear==5) Mn=month2004;

if (iyear==7) Mn=month2006;

Mn=Mnsplit(";");

var Dn="初一;初二;初三;初四;初五;初六;初七;初八;初九;初十;十一;十二;十三;十四;十五;十六;十七;十八;十九;二十;廿一;廿二;廿三;廿四;廿五;廿六;廿七;廿八;廿九;三十";

Dn=Dnsplit(";");

dayim=dayiy;

var total=new Array(13);

total[0]=parseInt(dpm[0]);

for (i=1;i<dpmlength-1;i++) total[i]=parseInt(dpm[i])+total[i-1];

for (i=dpmlength-1;i>0;i--)

if (dayim>total[i-1]){

dayim=dayim-total[i-1];

miy=i;

}

bsWeek=ww;

bsDate=yy+"年"+mm+"月";

bsDate2=dd;

bsYear="农历"+Yn[iyear];

bsYear2=Mn[miy]+Dn[dayim-1];

if (ss>=Ys[7]||ss<Ys[0]) bsYear=Yn[7];

function CAL(){

documentwrite("<table border='0' cellspacing='0' width='100%' bordercolor='#FFFFFF' cellpadding='0'>");

documentwrite("<tr><td align='center'><span style='FONT-SIZE: 12px'><font color=#666666>"+bsDate+"</font><font color=#666666>"+bsDate2+"日</font></span><font color=#666666><span style='FONT-SIZE: 14px'>");

documentwrite(" ");

documentwrite("<span style='FONT-SIZE: 12px'>"+bsWeek+"</span>"+"</font>");

documentwrite(" ");

documentwrite("<span style='FONT-SIZE: 12px'>"+"农历"+bsYear2+"</td></tr></table>");

}

//-->

</SCRIPT>

调用:<SCRIPT language=javascript>CAL();</SCRIPT>

以上就是关于C# 中 怎样获得当前星期以及农历时间全部的内容,包括:C# 中 怎样获得当前星期以及农历时间、C#的当天星期怎么获得、ASP中如何获取当前的星期数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9348199.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存