zoukankan      html  css  js  c++  java
  • Converted to the Calendar

    The  Chinese(Lunar) calendar Converted to the Gregorian calendar

    Code such as below:

    Auhtor : Jimmy Jun 16th 2010

    1)中国农历转公历(阳历)

     

    代码
    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);

    }

    2)西方公历(阳历) 转中国农历

    The Gregorian calendar Converted to the Chinese(Lunar) calendar.

     

    代码
    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);
    }

     the Calendar Transfer in Dyamics AX 4.0

     

    代码
    static void Jimmy_ChineseLunisolarDateAX4(Args _args)//AX4.0
    {
    Dialog dlg
    = new Dialog("Calendar conver to Chinese Lunisolar Date");
    DialogField dlgDate
    = dlg.addField(typeid(TransDate),"Calendar");
    DialogField dlgType
    = dlg.addField(typeid(Noyes),"公历转农历");
    TransDate Calendar;

    str
    100 ChineseLunisolarDate(TransDate 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);
    }

    str
    100 ChineseDateToSolarDate(TransDate ChineseDate)
    {
    int years,month,day,hour,minutes,second;
    TransDate CalendarStr;
    System.Globalization.ChineseLunisolarCalendar clc
    = new System.Globalization.ChineseLunisolarCalendar();

    ;
    years
    = year(ChineseDate);
    Month
    = mthofyr(ChineseDate);
    day
    = dayofmth(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);
    }
    ;
    dlgDate.value(today());
    dlg.doInit();
    if(!dlg.run())
    return ;

    if(dlgType.value())
    info(ChineseLunisolarDate(dlgDate.value()));
    else
    info(ChineseDateToSolarDate(dlgDate.value()));
    }

     the Calendar Transfer in Dyamics AX 2009

     

    代码
    static void Jimmy_ChineseLunisolarDateAX2009(Args _args)
    {
    CreatedDateTime Cdt;
    str
    50 ChineseLunisolarDate(Createddatetime ADataTime)
    {
    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;
    boolean isleapMonth,IsLeapYear;
    Str
    50 ChineseStr;

    System.Globalization.ChineseLunisolarCalendar clc
    = new System.Globalization.ChineseLunisolarCalendar();
    ;
    years
    = clc.GetYear(ADataTime);
    month
    = clc.GetMonth(ADataTime);
    day
    = clc.GetDayOfMonth(ADataTime);
    leapMonth
    = clc.GetLeapMonth(years);
    Weekday
    = clc.GetDayOfWeek(ADataTime);

    IsLeapYear
    = clc.IsLeapYear(years);
    print System.DateTime::IsLeapYear(years),Weekday;


    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);
    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;

    print strfmt(
    "%1年 %2月 %3日",years,month,day);
    return ChineseStr;
    }
    ;
    Cdt
    = dateTimeUtil::newDateTime(mkdate(19,12,1985),0);//My birthday 11初八
    Cdt = dateTimeUtil::newDateTime(today(),0);
    print Cdt;
    //dateTimeUtil::utcNow()
    Cdt = datetimeUtil::applyTimeZoneOffset(Cdt,datetimeutil::getCompanyTimeZone());

    print ChineseLunisolarDate(Cdt);
    print dateTimeUtil::getSystemDateTime();
    pause;

    }
    /*
    return System.String::Format("{0}{1} {2}年{3}{4}月{5}{6}"
    , "甲乙丙丁戊己庚辛壬癸"[(years - 4) % 10]
    , "子丑寅卯辰巳午未申酉戌亥"[(years - 4) % 12]
    , "鼠牛虎兔龙蛇马羊猴鸡狗猪"[(years - 4) % 12]
    , month == leapMonth ? "润" : ""
    , "无正二三四五六七八九十冬腊"[leapMonth > 0 && leapMonth <= month ? month - 1 : month]
    , "初十廿三"[day / 10]
    , "日一二三四五六七八九"[day % 10]
    */

     

  • 相关阅读:
    shell script入门
    perl环境配置以及Eclipse安装perl开发插件
    python注释
    Python中的sorted函数以及operator.itemgetter函数
    python 字典items和iteritems
    Python 字典(Dictionary) get()方法
    python numpy sum函数用法
    python numpy argsort函数用法
    python tile函数用法
    Shell之date用法
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1758961.html
Copyright © 2011-2022 走看看