CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

日期转换

楼主dengpingyy(dp)2005-04-11 16:30:52 在 Delphi / VCL组件开发及应用 提问

如何把2004-12-29这种日期转换为二00四年十二月二十九日? 问题点数:20、回复次数:4Top

1 楼senfore(来而不往非礼也!)回复于 2005-04-11 16:46:57 得分 2

你可以直接使用FromatDate进行格式化呀  
  然后将阿拉伯数字转为中文数字。  
   
  例如:formatDate('yyyy年mm月dd日   dddd   hh:mm:ss',NOW)  
   
  得到的是:2005年04月11日   星期一   16:48:58  
   
  然后你可以使用EnumToCnum函数将阿拉伯数字转为中文数字。  
  EnumToCnum函数是自己写的,你也可以到www.2ccc.com去查找。Top

2 楼dreamover(梦醒了〖http://hellfire.cn〗)回复于 2005-04-11 17:46:11 得分 0

function   cnFormatDate(Date:TDate):String;  
  var  
          tempDate:String;  
          i:Integer;  
  const  
          chrTen='T';  
          chrYear='J';  
          chrMonth='K';  
          chrDay='L';  
  begin  
   
   
  tempDate:=FormatDatetime('yyyy'+chrYear+'MM'+chrMonth+'dd'+chrDay,Date);  
   
  //日期转换  
  if   tempDate[9]='1'   then   tempDate[9]:=chrTen;  
  if   tempDate[9]   in   ['2','3']   then  
  begin  
          setlength(tempDate,12);  
          tempDate[12]:=tempDate[11];  
          tempDate[11]:=tempDate[10];  
          tempDate[10]:=chrTen;  
  end;  
   
  //月份转换  
  if   tempDate[6]='1'   then   tempDate[6]:=chrTen  
  else   begin  
          for   i:=6   to   length(tempDate)-1   do   tempDate[i]:=tempDate[i+1];  
          setlength(tempDate,length(tempDate)-1);  
  end;  
   
  tempDate:=stringreplace(tempDate,'0','零',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'1','一',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'2','二',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'3','三',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'4','四',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'5','五',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'6','六',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'7','七',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'8','八',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,'9','九',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,chrTen,'十',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,chrYear,'年',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,chrMonth,'月',[rfReplaceAll]);  
  tempDate:=stringreplace(tempDate,chrDay,'日',[rfReplaceAll]);  
   
   
  RESULT:=tempDate;  
  end;  
  Top

3 楼lyguo(愚人(每天顶几顶挣分升星星)http://zz.ihenan.cn/map/)回复于 2005-04-11 18:04:28 得分 5

这是我自己写的函数 我写的第一个。。就是它  
   
  function   EDatetoChinaDate(Edate:TDatetime):string;  
  var  
      i:integer;  
      tmp1:string;  
      sTmp1:String;  
      GzfTmp:string;  
      GZFint:integer;  
  begin  
      tmp1:=formatdatetime('yyyy-mm-dd',Edate);  
  if   length(tmp1)<8   then  
          MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);  
  FOR   I:=1   TO   4   DO  
      begin  
      GzfTmp:=COPY(tmp1,I,1);  
      GZFint:=strtoint(GzfTmp);  
          case   GZFint   of  
                1:   sTmp1:='一';//  
                2:   sTmp1:='二';//  
                3:   sTmp1:='三';//  
                4:   sTmp1:='四';//  
                5:   sTmp1:='五';//  
                6:   sTmp1:='六';//  
                7:   sTmp1:='七';//  
                8:   sTmp1:='八';//  
                9:   sTmp1:='九';//  
                0:   sTmp1:='0';//  
          end;  
      result:=result+sTmp1;  
      end;  
      result:=result+'年';  
      GzfTmp:=COPY(tmp1,6,1);  
      GZFint:=strtoint(GzfTmp);  
      case     GZFint   of  
                1:   sTmp1:='十';//  
                0:   sTmp1:='';//  
          else  
                sTmp1:='';  
      end;  
      result:=result+sTmp1;  
      GzfTmp:=COPY(tmp1,7,1);  
      GZFint:=strtoint(GzfTmp);  
          case   GZFint   of  
                1:   sTmp1:='一';//  
                2:   sTmp1:='二';//  
                3:   sTmp1:='三';//  
                4:   sTmp1:='四';//  
                5:   sTmp1:='五';//  
                6:   sTmp1:='六';//  
                7:   sTmp1:='七';//  
                8:   sTmp1:='八';//  
                9:   sTmp1:='九';//  
                0:   sTmp1:='';//  
          else  
                      MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);  
          end;  
      result:=result+sTmp1+'月';  
        GzfTmp:=COPY(tmp1,9,1);  
        GZFint:=strtoint(GzfTmp);  
      case   GZFint   of  
                1:   sTmp1:='十';//  
                2:   sTmp1:='二十';//  
                3:   sTmp1:='三十';//  
                0:   sTmp1:='';//  
          else  
              MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);  
      end;  
      result:=result+sTmp1;  
        GzfTmp:=COPY(tmp1,10,1);  
        GZFint:=strtoint(GzfTmp);  
          case   GZFint   of  
                1:   sTmp1:='一';//  
                2:   sTmp1:='二';//  
                3:   sTmp1:='三';//  
                4:   sTmp1:='四';//  
                5:   sTmp1:='五';//  
                6:   sTmp1:='六';//  
                7:   sTmp1:='七';//  
                8:   sTmp1:='八';//  
                9:   sTmp1:='九';//  
                0:   sTmp1:='';//  
          else  
                      MsgDlgEx('字符格式有误!',mtInformation,[mbOk],0);  
          end;  
    result:=result+sTmp1+'日';  
   
  end;  
   
  现在看来比较菜。。。呵呵,不过还可以用。。你试试Top

4 楼dreamover(梦醒了〖http://hellfire.cn〗)回复于 2005-04-11 19:09:57 得分 13

function   cnFormatDate(Date:TDate):String;  
  var  
          tempDate:String;  
          i:Integer;  
  const  
          chrTen='T';  
          chrYear='J';  
          chrMonth='K';  
          chrDay='L';  
  begin  
   
          tempDate:=FormatDatetime('yyyy'+chrYear+'MM'+chrMonth+'dd'+chrDay,Date);  
   
          //日期转换  
          if   tempDate[10]='0'   then   Delete(tempDate,10,1);  
   
          if   tempDate[9]   in   ['2','3']   then   insert(chrTen,tempDate,10);  
          if   tempDate[9]='1'   then   tempDate[9]:=chrTen;  
          if   tempDate[9]='0'   then   Delete(tempDate,9,1);  
   
          //月份转换  
          if   tempDate[7]='0'   then   Delete(tempDate,7,1);  
          if   tempDate[6]='1'   then   tempDate[6]:=chrTen   else   delete(tempDate,6,1);  
   
          tempDate:=stringreplace(tempDate,'0','零',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'1','一',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'2','二',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'3','三',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'4','四',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'5','五',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'6','六',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'7','七',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'8','八',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,'9','九',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,chrTen,'十',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,chrYear,'年',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,chrMonth,'月',[rfReplaceAll]);  
          tempDate:=stringreplace(tempDate,chrDay,'日',[rfReplaceAll]);  
   
          RESULT:=tempDate;  
   
  end;  
  刚才写的,十位后面的零忘去了,重写如上Top

相关问题

  • 日期转换
  • 日期转换
  • sql7.0 日期 转换
  • 日期转换问题?
  • 日期转换字符呦!!
  • 日期转换的问题
  • 日期转换格式
  • 日期转换问题!
  • 关于日期转换
  • 日期转换问题?

关键词

  • 转换
  • tempdate
  • rfreplaceall
  • stringreplace
  • chrten
  • 日期转换
  • yyyy
  • mm
  • tmp
  • dd

得分解答快速导航

  • 帖主:dengpingyy
  • senfore
  • lyguo
  • dreamover

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo