<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blogjava's web log

    blogjava's web log
    ...

    c sharp DateUtility

    ???? public ? static ? class ?DateUtility
    ????{
    ????????
    /// ? <summary>
    ????????
    /// ?Returns?the?first?day?of?the?year?for?a?given?date
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?BeginOfYear(DateTime?date)
    ????????{
    ????????????
    return ? new ?DateTime(date.Year,? 1 ,? 1 );
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Returns?the?last?day?of?the?year?for?a?given?date
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?EndOfYear(DateTime?date)
    ????????{
    ????????????
    return ? new ?DateTime(date.Year,? 12 ,? 31 );
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Returns?the?first?day?of?a?month?for?a?given?date
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?BeginOfMonth(DateTime?date)
    ????????{
    ????????????
    return ? new ?DateTime(date.Year,?date.Month,? 1 );
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Returns?the?last?day?of?a?month?for?a?given?date
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"> Date </param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?EndOfMonth(DateTime?date)
    ????????{
    ????????????
    int ?year? = ?date.Year;
    ????????????
    int ?month? = ?date.Month;
    ????????????
    if ?(month? == ? 12 )
    ????????????{
    ????????????????year
    ++ ;
    ????????????????month
    = 1 ;
    ????????????}
    ????????????
    else
    ????????????????month
    ++ ;
    ????????????
    return ? new ?DateTime(year,month, 1 ).AddDays( - 1 );
    ????????}


    ????????
    /// ? <summary>
    ????????
    /// ?Returns?the?first?day?of?a?quarter
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?BeginOfQuarter(DateTime?date)
    ????????{
    ????????????
    int ?month? = ?(((date.Month? - 1 )? / ? 3 ) * 3 ) + 1 ;
    ????????????
    return ? new ?DateTime(date.Year,?month,? 1 );
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Returns?the?last?day?of?a?quarter
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"> Date </param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?EndOfQuarter(DateTime?date)
    ????????{
    ????????????
    return ?BeginOfQuarter(BeginOfMonth(date).AddMonths( + 3 )).AddDays( - 1 );
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Check?if?the?date?is?in?a?leapyear
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"> Date </param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ? bool ?LeapYear(DateTime?date)
    ????????{
    ????????????
    int ?year? = ?date.Year;
    ????????????
    return ?(year? % ? 4 ? == ? 0 )? && ?((year? % ? 100 ? != ? 0 )? || ?(year? % ? 400 ? == ? 0 ));
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Caclulates?the?weeknumber?for?a?given?date
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"> Date </param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ? int ?WeekOfYear(DateTime?date)
    ????????{????????????
    ????????????
    int []?t1? = ? new ? int [ 7 ]?{ - 1 ,?? 0 ,?? 1 ,?? 2 ,?? 3 ,? - 3 ,? - 2 };
    ????????????
    int []?t2? = ? new ? int [ 7 ]?{ - 4 ,?? 2 ,?? 1 ,?? 0 ,? - 1 ,? - 2 ,? - 3 };

    ????????????DateTime?newYear?
    = ?BeginOfYear(date);
    ????????????
    int ?doy1? = ?date.DayOfYear? + ?t1[( int )newYear.DayOfWeek];
    ????????????
    int ?doy2? = ?date.DayOfYear? + ?t2[( int )date.DayOfWeek];

    ????????????
    if ?(doy1? <= ? 0 )?
    ????????????????
    return ?WeekOfYear(newYear.AddDays( - 1 ));
    ????????????
    else
    ????????????????
    if ?(doy2? >= ?EndOfYear(newYear).DayOfYear?)
    ????????????????????
    return ? 1 ;
    ????????????????
    else
    ????????????????????
    return ?(doy1 - 1 ) / 7 ? + 1 ;
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Determines?how?much?days?a?month?has
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="date"> Date </param>
    ????????
    /// ? <returns> Number?of?days?in?the?month </returns>
    ???????? public ? static ? int ?DaysInMonth(DateTime?date)
    ????????{
    ????????????
    short []?daysPerMonth? = ? new ? short [ 12 ]?{? 31 ,? 28 ,? 31 ,? 30 ,? 31 ,? 30 ,? 31 ,? 31 ,? 30 ,? 31 ,? 30 ,? 31 ?};
    ????????????
    int ?month? = ?date.Month;
    ????????????
    if ?(month? == ? 2 ? && ?LeapYear(date))
    ????????????????
    return ?daysPerMonth[month? - ? 1 ]? + ? 1 ;
    ????????????
    else
    ????????????????
    return ?daysPerMonth[month? - ? 1 ];
    ????????}


    ????????
    /// ? <summary>
    ????????
    /// ?Return?the?duration?between?two?dates?in?months
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="start"></param>
    ????????
    /// ? <param?name="end"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ? int ?AgeInMonths(DateTime?start,?DateTime?end)
    ????????{
    ????????????
    return ?(end.Year - start.Year)? * ? 12 ? + ?(end.Month - start.Month);
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Return?the?duration?between?two?dates?in?years
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="start"></param>
    ????????
    /// ? <param?name="end"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ? int ?AgeInYears(DateTime?start,?DateTime?end)
    ????????{
    ????????????
    return ?AgeInMonths(start,?end)? / ? 12 ;
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Return?the?duration?until?today?in?months
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="start"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ? int ?AgeInMonths(DateTime?start)
    ????????{
    ????????????
    return ?AgeInMonths(start,?DateTime.Today);
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Return?the?duration?until?today?in?years
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="start"></param>
    ????????
    /// ? <param?name="end"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ? int ?AgeInYears(DateTime?start)
    ????????{
    ????????????
    return ?AgeInYears(start,?DateTime.Today);
    ????????}

    ????????
    /// ? <summary>
    ????????
    /// ?Calculate?the?easter?holiday?for?a?year
    ????????
    /// ? </summary>
    ????????
    /// ? <param?name="year"></param>
    ????????
    /// ? <returns></returns>
    ???????? public ? static ?DateTime?Easter( int ?year)
    ????????{
    ????????????
    int ?month;
    ????????????
    int ?day;

    ????????????
    int ?k1? = ? 24 ;
    ????????????
    int ?k2? = ? 5 ;

    ????????????
    int ?r1? = ?year? % ? 19 ;
    ????????????
    int ?r2? = ?year? % ? 4 ;
    ????????????
    int ?r3? = ?year? % ? 7 ;
    ????????????
    int ?r4? = ?( 19 ? * ?r1? + ?k1)? % ? 30 ;
    ????????????
    int ?r5? = ?( 2 ? * ?r2? + ? 4 ? * ?r3? + ? 6 ? * ?r4? + ?k2)? % ? 7 ;
    ????????????
    int ?A?? = ? 22 ? + ?r4? + ?r5;

    ????????????
    if ?(A? < ? 32 )?
    ????????????{
    ????????????????month?
    = ? 3 ;
    ????????????????day?
    = ?A;
    ????????????}
    ????????????
    else
    ????????????{
    ????????????????A?
    = ?r4? + ?r5? - ? 9 ;
    ????????????????month?
    = ? 4 ;
    ????????????????
    if ?(A? == ? 26 )
    ????????????????????day?
    = ? 19 ;
    ????????????????
    else ? if ?(A? != ? 25 )?
    ????????????????????day?
    = ?A;
    ????????????????
    else ? if ?(r4? == ? 18 ?? && ?r5? > ? 10 )
    ????????????????????day?
    = ? 18 ;
    ????????????????
    else
    ????????????????????day?
    = ? 25 ;
    ????????????}
    ????????????
    ????????????
    return ? new ?DateTime(year,month,day);
    ????????}
    ????}

    posted on 2007-01-22 13:42 record java and net 閱讀(209) 評(píng)論(0)  編輯  收藏 所屬分類: 常用配置代碼


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動(dòng)態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評(píng)論

    主站蜘蛛池模板: 亚洲国产精品尤物YW在线观看| mm1313亚洲国产精品美女| 亚洲熟妇无码爱v在线观看| 久久久久久免费视频| 亚洲精品又粗又大又爽A片| 亚洲国产一级在线观看| 久久久久免费看黄a级试看| 久久亚洲最大成人网4438| 亚洲国产精品一区二区九九 | 高清国语自产拍免费视频国产| 国产成人综合亚洲一区| 亚洲色大成网站WWW久久九九| 1000部免费啪啪十八未年禁止观看 | 亚洲一级毛片免费看| 亚洲乱码中文字幕手机在线 | 亚洲sm另类一区二区三区| 久久久久噜噜噜亚洲熟女综合| 久久国产精品免费观看| 亚洲精品无码久久久久牙蜜区| 亚洲日本国产精华液| 亚洲精品国产高清嫩草影院| 免费观看男人免费桶女人视频 | 亚洲一区二区三区成人网站| 国产成人99久久亚洲综合精品| 麻花传媒剧在线mv免费观看| 久久精品国产免费一区| 亚洲人成网站18禁止| 亚洲av无码电影网| 亚洲国产福利精品一区二区| 亚洲精品国产综合久久一线| 四虎国产精品免费久久影院| 国产精品色拉拉免费看| 亚洲一级片免费看| 亚洲午夜成人精品无码色欲| 丁香婷婷亚洲六月综合色| 麻豆狠色伊人亚洲综合网站| 色偷偷女男人的天堂亚洲网| 亚洲欧洲国产综合AV无码久久| 亚洲字幕AV一区二区三区四区| 亚洲色成人网站WWW永久四虎| 亚洲精品无码永久在线观看男男|