请问一下:现在正在做 从PC发送日期时间到LED显示出来, 
          SendTime2Led(led_list[i], FormatDatetime('   hh:nn', now));
          由于LED屏问题,显示时间数字时间比较小,现在如何把时间处理成汉字编码再转发过去LED屏呢?请赐教

解决方案 »

  1.   

    首部 procedure DecodeTime(const DateTime: TDateTime; var Hour, Min, Sec, MSec: Word); $[SysUtils.pas
    功能 分解时间为时、分、秒、微妙
    说明 <NULL>
    参考 function SysUtils.DateTimeToTimeStamp
    例子
    ///////Begin DecodeTime
    procedure TForm1.Button1Click(Sender: TObject);
    var
    Hour, Min, Sec, MSec: Word;
    begin
    DecodeTime(Time, Hour, Min, Sec, MSec);
      

  2.   

    这玩意,自己写个函数就能截取。比如:
    //取系统时间
    SysDate := FormatDateTime('yyyymmddhhnnss',Now);
    //分解时间
    Year := Copy(SysDate,1,4);
    Month:= Copy(SysDate,5,2);
    Day  := Copy(SysDate,7,3);
    ....
    前提是你的时间格式一定要用FormatDateTiem格式化了。当然了还有其他系统函数也可以实现。但我懒的找了。
      

  3.   

    在dateutil单元里,有yearof,monthof,dayof等获取各个值的函数,参数是datetime类型
      

  4.   

    1 format里用-来区分年月日时分秒,然后就是字符串截取了
    2 或者直接用函数分别获取也可以,方法很多,随便举个例子
    DateTimeToString(s1,'hh',now);
    s1就是小时
      

  5.   

    我的代码如下:
    function decodetimeToWord: String;
    var
        Hour, Min, Sec, MSec: Word;
        time : TDateTime ;
    begin
       time := strtotime(FormatDatetime('hh:nn', now));
       DecodeTime(time, Hour, Min, Sec, MSec);
    end;
    但是如何返会一个String类型的时和分呢?以及中间两点,主要是要将'hh:nn'转为占两个字节的中文一样的字符串,请高手们指导指导
      

  6.   

    谢谢楼上提醒哦~现在本人把代码show出来,看看有没有更好更简洁的写法,请高人指导~~
    function timeToUnicode( ):String;
    var
        i: Integer;
        sysTime, sTemp1, sTemp2, sTemp3, sTemp4 : String;
        hour1,hour2,min1,min2 : Integer;
        Const number : array[0..9] of string =('0','1','2','3','4','5','6','7','8','9');
    begin
        sysTime :=  FormatDatetime('hh:nn', now);
        //分解时间
        hour1 := strToInt( Copy(sysTime,1,1) );
        hour2 := strToInt( Copy(sysTime,2,1) );
        min1 := strToInt( Copy(sysTime,4,1) );
        min2 := strToInt( Copy(sysTime,5,1) );    for i := 0 to 9 do
        begin
           if hour1 = i then
              sTemp1 := number[i];
           if hour2 = i then
              sTemp2 := number[i];
           if min1 = i then
              sTemp3 := number[i];
           if min2 = i then
              sTemp4 := number[i];
        end;    AppendStr( sTemp1, sTemp2 );
        AppendStr( sTemp1, ' £º ' );    AppendStr( sTemp1, sTemp3 );
        AppendStr( sTemp1, sTemp4 );    Result := Result + sTemp1;
    end;
      

  7.   

    楼主为什么不用DecodeTime这个方法啊??
      

  8.   

    FormatDateTime('yyyy"年"MM"月"dd"日"hh"时"mm"分"ss"秒"zzz"毫秒"', now);
      

  9.   

    到底是需要全角0123还是中文零一二三呀?不过都能查表。
    用DecodeTime然后查表简单一些。
      

  10.   

    呵呵~是需要全角的 0123,用DecodeTime具体咋样实现呢?然后查表?请具体一点吧~
      

  11.   


     xxx  : array[0..9] of string=('0','1'var
     Hour, Min, Sec, MSec: Word;
     time : TDateTime ;
    begin
     time := now;
     DecodeTime(time, Hour, Min, Sec, MSec);
     result:=xxx[Hour div 10]+xxx[Hour mod 10]+":"+xxx[Min div 10]+xxx[Min mod 10];
    end;