<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) 評論(0)  編輯  收藏 所屬分類: 常用配置代碼

    導航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 精品日韩亚洲AV无码一区二区三区 | 国产 亚洲 中文在线 字幕| 久久久免费的精品| 久久精品亚洲综合| 性xxxx视频免费播放直播| 亚洲国产第一页www| 99久热只有精品视频免费观看17| 亚洲AV综合色区无码另类小说| 免费无码黄网站在线看| 亚洲v高清理论电影| 2021国内精品久久久久精免费| 亚洲精品国产情侣av在线| 日韩免费精品视频| 亚洲色成人四虎在线观看| 日本高清免费不卡在线| 污视频网站在线免费看| 曰韩亚洲av人人夜夜澡人人爽 | 亚洲精品无码午夜福利中文字幕 | 麻豆高清免费国产一区| 亚洲午夜精品国产电影在线观看| 99在线视频免费观看视频| 亚洲日韩精品无码AV海量| 无码专区一va亚洲v专区在线| 成人片黄网站色大片免费观看cn| 亚洲第一极品精品无码久久| 5555在线播放免费播放| 四虎必出精品亚洲高清| 亚洲美女在线国产| 热re99久久6国产精品免费| 亚洲毛片基地4455ww| 亚洲成a人在线看天堂无码| 国产精品免费AV片在线观看| 亚洲av无码一区二区三区天堂古代| 成人性生交视频免费观看| 免费人成网站永久| 综合自拍亚洲综合图不卡区| 国产成人免费一区二区三区| 西西人体免费视频| 亚洲综合色婷婷在线观看| a级亚洲片精品久久久久久久 | 2019亚洲午夜无码天堂|