国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

根據(jù)時(shí)間日期格式從字符串中解析日期時(shí)間

2019-11-18 18:13:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
根據(jù)時(shí)間日期格式從字符串中解析日期時(shí)間
function StrToDtFmt(const S, Fmt: String; Dft: TDateTime): TDateTime;

function StrToDtFmt(const S, Fmt: String; Dft: TDateTime): TDateTime;
var
  Pts: array[1..10] of Integer;
  Wds: array[1..10] of Integer;
  Vls: array[1..10] of Word;
  i, j, n, m, k, d: Integer;
  t: String;
  c: Char;
  dt: TDateTime;
begin
  // 只處理數(shù)字格式的日期和時(shí)間
  i := 1;
  n := 1;    
  t := Trim(AnsiUpperCase(Fmt));
  // 解析格式串
  while i <= Length(t) do
  begin
    case t[i] of
      'Y': Pts[n] := 1;
      'M': Pts[n] := 2;
      'D': Pts[n] := 3;
      'H': Pts[n] := 4;
      'N': Pts[n] := 5;
      'S': Pts[n] := 6;
      'Z': Pts[n] := 7;
      else
      begin
        i := i + 1;
        Continue;
      end;
    end;
    c := t[i];
    i := i + 1;
    m := 1;
    while t[i] = c do
    begin
      Inc(i);
      Inc(m);
    end;
    if t[i] in ['Y','M','D','H','N','S','Z'] then
      Wds[n] := m
    else
      Wds[n] := 0;
    n := n + 1;
    if n > 7 then Break;
  end;
  n := n - 1;
  // 開(kāi)始轉(zhuǎn)化
  Result := Dft;
  if Length(S) <= 0 then Exit;
  DecodeDate(Result, Vls[1], Vls[2], Vls[3]);
  DecodeTime(Result, Vls[4], Vls[5], Vls[6], Vls[7]);
  m := 1;
  i := 1;
  k := Length(S);
  while m <= n do
  begin
    while not (S[i] in ['0'..'9', #0]) do Inc(i);
    if i > k then Break;
    d := 0;
    j := i;
    while (S[i] in ['0'..'9']) and
      ((Wds[m] <= 0) or (i - j < Wds[m])) do
    begin
      d := d * 10 + Ord(S[i]) - Ord('0');
      i := i + 1;
    end;
    Vls[Pts[m]] := d;
    if i > k then Break;
    m := m + 1;
  end;
  if TryEncodeDate(Vls[1], Vls[2], Vls[3], dt) then
    Result := Int(dt) + Frac(Result);
  if TryEncodeTime(Vls[4], Vls[5], Vls[6], Vls[7], dt) then
    Result := Int(Result) + Frac(dt);
end;

上一篇:程序字體,我們自已選

下一篇:查句柄知多少

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
學(xué)習(xí)交流
熱門(mén)圖片

新聞熱點(diǎn)

疑難解答

圖片精選

網(wǎng)友關(guān)注

主站蜘蛛池模板: 钦州市| 霍林郭勒市| 大安市| 镇坪县| 安图县| 吉木乃县| 盐津县| 平果县| 通化市| 肇州县| 九龙城区| 潍坊市| 承德市| 揭西县| 孝昌县| 潼南县| 来凤县| 岳池县| 大新县| 九江县| 沐川县| 兰西县| 长泰县| 阿合奇县| 财经| 垫江县| 蚌埠市| 新兴县| 吉林省| 北安市| 临安市| 宜兰市| 白城市| 广水市| 大丰市| 图木舒克市| 措美县| 开原市| 渝中区| 广汉市| 雅江县|