如题,字符串为 0B0C0105362E 请问Delphi里如何进行转换,得到正常的时间字符串?

解决方案 »

  1.   

    有Java的源码如下,可否改成Delphi的?
    public static  String getSimpleFormatDateTime(String hexDateTime) {
    int[] iDateTiem = new int[6]; for (int j = 1; j <= 6; j++) {
    iDateTiem[j - 1] = Integer.parseInt(hexDateTime.substring(
    (j - 1) * 2, j * 2), 16);
    } String head = "20";
    if ((iDateTiem[0] + "").length() == 1)
    head = "200";
    return head + iDateTiem[0] + "-" + iDateTiem[1] + "-" + iDateTiem[2]
    + " " + iDateTiem[3] + ":" + iDateTiem[4] + ":" + iDateTiem[5];
    }
      

  2.   

    function getSimpleFormatDateTime(const hexDateTime: string): string;
    var
      iDateTime: array[0..5] of Integer;
      i: Integer;
    begin
      for i := 1 to 6 do
      begin
        iDateTime[i - 1] := StrToInt('$' + Copy(hexDateTime, i * 2 - 1, 2));
      end;
      Result := Format('20%.2d-%.2d-%.2d %.2d:%.2d:%.2d', [iDateTime[0], iDateTime[1],
        iDateTime[2], iDateTime[3], iDateTime[4], iDateTime[5]]);
    end;
    没做容错。
    ShowMessage(getSimpleFormatDateTime('0B0C0105362E'));
      

  3.   

    多谢3楼pathletboy的解答,给分了!