2012年5月20日星期日
How to changed Chinese date and Solar Date
display str 100 ChineseDateTime()
{
str 100 name;
str 100 SolarCalendarToChinese(TransDateTime CalendarDateTime)
{
int years,month,day,leapMonth,Weekday;
Container J = ['甲',"乙",'丙','丁','戊','己','庚','辛','壬','癸'];
Container z = ["子","丑","寅","卯","巳","午","未","申","酉","戌","亥"];
Container s = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];
Container w = ["无","正","二","三","四","五","六","七","八","九","十","冬","腊"];
Container c = ["初","十","廿","三"];
Container r = ["日","一","二","三","四","五","六","七","八","九"];
Container wd = ['日',"一","二","三","四","五","六"];
Str 20 jj,zz,ss,ww,cc,rr,rn,ry,wkday;
Str 100 ChineseStr;
System.Globalization.ChineseLunisolarCalendar clc;
boolean isleapMonth,IsLeapYear;
;
clc = new System.Globalization.ChineseLunisolarCalendar();
years = clc.GetYear(CalendarDateTime);
month = clc.GetMonth(CalendarDateTime);
day = clc.GetDayOfMonth(CalendarDateTime);
leapMonth = clc.GetLeapMonth(years);
Weekday = clc.GetDayOfWeek(CalendarDateTime);
IsLeapYear = clc.IsLeapYear(years);
jj = Conpeek(J,(years - 4) MOD 10 + 1);
zz = Conpeek(Z,(years - 4) MOD 12 + 1);
SS = Conpeek(S,(years - 4) MOD 12 + 1);
//wkday = '星期' + Conpeek(wd,Weekday + 1);
wkday = dayname(Weekday);
if (leapMonth > 0)
{
if (leapMonth == month) //闰月
{
isleapMonth = true;
ry = '闰月';
month = month - 1;
}
else if (month > leapMonth)
{
month = month - 1;
}
}
WW = Conpeek(W,month + 1);
cc = ConPeek(C,day / 10 + 1);
rr = ConPeek(R,day mod 10 + 1);
if(leapMonth)
ry = '润';
else
ry = '平';
if(IsLeapYear)
rn = '润';
else
rn = '平';
//ChineseStr = strfmt("%1%2%3(%8)年(%4)%5月 %6%7日" ,JJ,ZZ,ss,ry,WW,cc,rr,rn)+ wkday;
//return ChineseStr + strfmt(" %1年 %2月 %3日",years,month,day);
return "[ " + strfmt("%1%2%3 (%8) %9 年(%4) %5 月 %6%7 日 " ,JJ,ZZ,ss,ry,WW,cc,rr,rn,years) + "]";
}
str 100 ChineseToSolarCalendar(TransDateTime ChineseDate)
{
int years,month,day,hour,minutes,second;
TransDateTime CalendarStr;
System.Globalization.ChineseLunisolarCalendar clc = new System.Globalization.ChineseLunisolarCalendar();
;
years = datetimeutil::year(ChineseDate);
Month = datetimeutil::month(ChineseDate);
day = datetimeutil::day(ChineseDate);
hour = datetimeutil::hour(ChineseDate);
minutes = datetimeutil::minute(ChineseDate);
second = datetimeutil::second(ChineseDate);
CalendarStr = clc.ToDateTime(years,Month,day,hour,minutes,second,0);
return strfmt("农历 : %1;公历:%2",ChineseDate,CalendarStr);
}
;
name = strfmt("%1 %2",datetimeutil::applyTimeZoneOffset(datetimeutil::utcNow(),datetimeutil::getCompanyTimeZone()),
dayname(dayOfWk(today())));
name += " " + SolarCalendarToChinese(datetimeutil::newDateTime(systemdateget(),0,0));
DateTimeStr.text(name);
if(Loop.value())
this.setTimeOut(identifierstr(ChineseDateTime), 500, true);
return name;
}
-------------
阳历转农历
static TransDate solarDateToChineseDate(TransDate _TransDate)
{
/**公历转换成农历*/
System.Globalization.ChineseLunisolarCalendar cCalendar = new System.Globalization.ChineseLunisolarCalendar();
TransDate GetChineseDateTime(Date datetime)
{
int lyear = cCalendar.GetYear(datetime);
int lmonth = cCalendar.GetMonth(datetime);
int lday = cCalendar.GetDayOfMonth(datetime);
//获取闰月, 0 则表示没有闰月
int leapMonth = cCalendar.GetLeapMonth(lyear);
boolean isleap = false;
if (leapMonth > 0)
{
if (leapMonth == lmonth)
{
//闰月
isleap = true;
lmonth--;
}
else if (lmonth > leapMonth)
{
lmonth--;
}
}
//return strfmt("%1年%2月%3日",lyear,lmonth,lday);
return mkdate(lday,lmonth,lyear);
}
;
return GetChineseDateTime(_TransDate);
}
-------------------------
农历转阳历
static TransDate ChineseDateToSolarDate(TransDate ChineseDate)
{
/**农历转换成公历*/
System.Globalization.ChineseLunisolarCalendar clc = new System.Globalization.ChineseLunisolarCalendar();
int years,month,day,hour,minutes,second;
TransDate transDate;
;
years = year(ChineseDate);
Month = mthofyr(ChineseDate);
day = dayofmth(ChineseDate);
// hour = datetimeutil::hour(ChineseDate);
// minutes = datetimeutil::minute(ChineseDate);
// second = datetimeutil::second(ChineseDate);
transDate = clc.ToDateTime(years,Month,day,hour,minutes,second,0);
return transDate;//strfmt("农历 : %1;公历:%2",ChineseDate,CalendarStr);
}
订阅:
博文评论 (Atom)
没有评论:
发表评论