转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
日历函数单元         ★★★★

日历函数单元

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3120 更新时间:2009/4/23 18:26:14
$78, $87, $87, //2030
    $A5, $B4, $96, $A5, $96, $96, $88, $78, $78, $78, $87, $87, //2031
    $95, $B4, $A5, $B4, $A5, $A6, $97, $87, $87, $78, $87, $96, //2032
    $A5, $C3, $A5, $B5, $A6, $A6, $88, $88, $88, $78, $87, $86, //2033
    $A5, $B3, $A5, $A5, $A6, $A6, $88, $78, $88, $78, $87, $87, //2034
    $A5, $B4, $96, $A5, $A6, $96, $88, $88, $78, $78, $87, $87, //2035
    $95, $B4, $A5, $B4, $A5, $A6, $97, $87, $87, $78, $87, $96, //2036
    $A5, $C3, $A5, $B5, $A6, $A6, $87, $88, $88, $78, $87, $86, //2037
    $A5, $B3, $A5, $A5, $A6, $A6, $88, $88, $88, $78, $87, $87, //2038
    $A5, $B4, $96, $A5, $A6, $96, $88, $88, $78, $78, $87, $87, //2039
    $95, $B4, $A5, $B4, $A5, $A6, $97, $87, $87, $78, $87, $96, //2040
    $A5, $C3, $A5, $B5, $A5, $A6, $87, $88, $87, $78, $87, $86, //2041
    $A5, $B3, $A5, $B5, $A6, $A6, $88, $88, $88, $78, $87, $87, //2042
    $A5, $B4, $96, $A5, $A6, $96, $88, $88, $78, $78, $87, $87, //2043
    $95, $B4, $A5, $B4, $A5, $A6, $97, $87, $87, $88, $87, $96, //2044
    $A5, $C3, $A5, $B4, $A5, $A6, $87, $88, $87, $78, $87, $86, //2045
    $A5, $B3, $A5, $B5, $A6, $A6, $87, $88, $88, $78, $87, $87, //2046
    $A5, $B4, $96, $A5, $A6, $96, $88, $88, $78, $78, $87, $87, //2047
    $95, $B4, $A5, $B4, $A5, $A5, $97, $87, $87, $88, $86, $96, //2048
    $A4, $C3, $A5, $A5, $A5, $A6, $97, $87, $87, $78, $87, $86, //2049
    $A5, $C3, $A5, $B5, $A6, $A6, $87, $88, $78, $78, $87, $87); //2050

function WeekDay(iYear, iMonth, iDay: Word): Integer;
begin
  Result := DayOfWeek(EncodeDate(iYear, iMonth, iDay));
end;

function WeekNum(const TDT: TDateTime): Word;
var
  Y, M, D: Word;
  dtTmp: TDateTime;
begin
  DecodeDate(TDT, Y, M, D);
  dtTmp := EnCodeDate(Y, 1, 1);
  Result := (Trunc(TDT - dtTmp) + (DayOfWeek(dtTmp) - 1)) div 7;
  if Result = 0 then
    Result := 51
  else
    Result := Result - 1;
end;

function WeekNum(const iYear, iMonth, iDay: Word): Word;
begin
  Result := WeekNum(EncodeDate(iYear, iMonth, iDay));
end;

function MonthDays(iYear, iMonth: Word): Word;
begin
  case iMonth of
    1, 3, 5, 7, 8, 10, 12:
      Result := 31;
    4, 6, 9, 11:
      Result := 30;
    2: //如果是闰年
      if IsLeapYear(iYear) then
        Result := 29
      else
        Result := 28;
  else
    Result := 0;
  end;
end;

function GetLeapMonth(iLunarYear: Word): Word;
var
  Flag: Byte;
begin
  Flag := gLunarMonth[(iLunarYear - START_YEAR) div 2];
  if (iLunarYear - START_YEAR) mod 2 = 0 then
    Result := Flag shr 4
  else
    Result := Flag and $0F;
end;

function LunarMonthDays(iLunarYear, iLunarMonth: Word): Longword;
var
  Height, Low: Word;
  iBit: Integer;
begin
  if iLunarYear < START_YEAR then
  begin
    Result := 30;
    Exit;
  end;
  Height := 0;
  Low := 29;
  iBit := 16 - iLunarMonth;
  if (iLunarMonth > GetLeapMonth(iLunarYear)) and (GetLeapMonth(iLunarYear) > 0) then
    Dec(iBit);
  if (gLunarMonthDay[iLunarYear - START_YEAR] and (1 shl iBit)) > 0 then
    Inc(Low);
  if iLunarMonth = GetLeapMonth(iLunarYear) then
    if (gLunarMonthDay[iLunarYear - START_YEAR] and (1 shl (iBit - 1))) > 0 then
      Height := 30
    else
      Height := 29;
  Result := MakeLong(Low, Height);
end;

function LunarYearDays(iLunarYear: Word): Word;
var
  Days, i: Word;
  tmp: Longword;
begin
  Days := 0;
  for i := 1 to 12 do
  begin
    tmp := LunarMonthDays(iLunarYear, i);
    Days := Days + HiWord(tmp);
    Days := Days + LoWord(tmp);
  end;
  Result := Days;
end;

procedure FormatLunarYear(iYear: Word; var pBuffer: string);
var
  szText1, szText2, szText3: string;
begin
  szText1 := ''''甲乙丙丁戊己庚辛壬癸'''';
  szText2 := ''''子丑寅卯辰巳午未申酉戌亥'''';
  szText3 := ''''鼠牛虎免龙蛇马羊猴鸡狗猪'''';
  pBuffer := Copy(szText1, ((iYear - 4) mod 10) * 2 + 1, 2);
  pBuffer := pBuffer + Copy(szText2, ((iYear - 4) mod 12) * 2 + 1, 2);
  pBuffer := pBuffer + '''' '''';
  pBuffer := pBuffer + Copy(szText3, ((iYear - 4) mod 12) * 2 + 1, 2);
  pBuffer := pBuffer + ''''年'''';
end;

function FormatLunarYear(iYear: Word): string;
var
  pBuffer: string;
begin
  FormatLunarYear(iYear, pBuffer);
  Result := pBuffer;
end;

procedure FormatMonth(iMonth: Word; var pBuffer: string; bLunar: Boolean);
var
  szText: string;
begin
  if (not bLunar) and (iMonth = 1) then
  begin
    pBuffer := ''''  一月'''';
    Exit;
  end;
  szText := ''''正二三四五六七八九十'''';
  if iMonth <= 10 then
  begin
    pBuffer := ''''  '''';
    pBuffer := pBuffer + Copy(szText, (iMonth - 1) * 2 + 1, 2);
    pBuffer := pBuffer + ''''月'''';
    Exit;
  end;
  if iMonth = 11 then
    pBuffer := ''''十一''''
  else
    pBuffer := ''''十二'''';
  pBuffer := pBuffer + ''''月'''';
end;

function FormatMonth(iMonth: Word; bLunar: Boolean): string;
var
  pBuffer: string;
begin
  FormatMonth(iMonth, pBuffer, bLunar);
  Result := pBuffer;
end;

procedure FormatLunarDay(iDay: Word; var pBuffer: string);
var
  szText1, szText2: string;
begin
  szText1 := ''''初十廿三'''';
  szText2 := ''''一二三四五六七八九十'''';
  if (iDay <> 20) and (iDay <> 30) then
  begin
    pBuffer := Copy(szText1, ((iDay - 1) div 10) * 2 + 1, 2);
    pBuffer := pBuffer + Copy(szText2, ((iDay - 1) mod 10) * 2 + 1, 2);
  end
  else
  begin
    pBuffer := Copy(szText1, (iDay div 10) * 2 + 1, 2);
    pBuffer := pBuffer + ''''十'''';
  end;
end;

function FormatLunarDay(iDay: Word): string;
var
  pBuffer: string;
begin
  FormatLunarDay(iDay, pBuffer);
  Result := pBuffer;
end;

function CalcDateDiff(iEndYear, iEndMonth, iEndDay: Word; iStartYear: Word; iStartMonth: Word; iStartDay: Word): Longword;
begin
  Result := Trunc(EncodeDate(iEndYear, iEndMonth, iEndDay) - EncodeDate(iStartYear, iStartMonth, iStartDay));
end;

function CalcDateDiff(EndDate, StartDate: TDateTime): Longword;
begin
  Result := Trunc(EndDate - StartDate);
end;

function GetLunarDate(iYear, iMonth, iDay: Word; var iLunarYear, iLunarMonth, iLunarDay: Word): Word;
begin
  l_CalcLunarDate(iLunarYear, iLunarMonth, iLunarDay, CalcDateDiff(iYear, iMonth, iDay));
  Result := l_GetLunarHolDay(iYear, iMonth, iDay);
end;

procedure GetLunarDate(InDate: TDateTime; var iLunarYear, iLunarMonth, iLunarDay: Word);
begin
  l_CalcLunarDate(iLunarYear, iLunarMonth, iLunarDay, CalcDateDiff(InDate, EncodeDate(START_YEAR, 1, 1)));
end;

procedure l_CalcLunarDate(var iYear, iMonth, iDay: Word; iSpanDays: Longword);
var
  tmp: Longword;
begin
  //阳历1901年2月19日为阴历1901年正月初一
  //阳历1901年1月1日到2月19日共有49天
  if iSpanDays < 49 then
  begin
    iYear := START_YEAR - 1;
    if iSpanDays < 19 then
    begin
      iMonth := 11;
      iDay := 11 + Word(iSpanDays);
    end
    else
    begin
      iMonth := 12;
      iDay := Word(iSpanDays) - 18;
    end;
    Exit;
  end;
  //下面从阴历1901年正月初一算起
  iSpanDays := iSpanDays - 49;
  iYear := START_YEAR;
  iMonth := 1;
  iDay := 1;
  //计算年
  tmp := LunarYearDays(iYear);
  while iSpanDays >= tmp do
  begin
    iSpanDays := iSpanDays - tmp;
    Inc(iYear);
    tmp := LunarYearDays(iYear);
  end;
  //计算月
  tmp := LoWord(LunarMonthDays(iYear, iMonth));
  while iSpanDays >= tmp do
  begin
    iSpanDays := iSpanDays - tmp;
    if iMonth = GetLeapMonth(iYear) then
    begin
      tmp := HiWord(LunarMonthDays(iYear, iMonth));
      if iSpanDays < tmp then
        Break;
      iSpanDays := iSpanDays - tmp;
    end;
    Inc(iMonth);
    tmp := LoWord(LunarMonthDays(iYear, iMont

上一页  [1] [2] [3] [4]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台