zoukankan      html  css  js  c++  java
  • Iso8601 日期格式

    unit Iso8601Unit;
    
    interface
    
    type
      TIso8601 = class(TObject)
      public
        class function DateTimeFromIso8601(const Value: string): TDateTime; static;
        class function UtcDateTimeToIso8601(const Value: TDateTime): string; static;
        class function DateTimeToIso8601(const Value: TDateTime): string; static;
        class function UtcNow: TDateTime; static;
        class function ToUtc(const Value: TDateTime): TDateTime; static;
        class function FromUtc(const Value: TDateTime): TDateTime; static;
      end;
    
    implementation
    
    uses
      IdGlobalProtocols, {IdGlobal for Index}   SysUtils,
      XSBuiltIns;
    
    class function TIso8601.DateTimeFromIso8601(const Value: string): TDateTime;
    begin
      with TXSDateTime.Create() do
      try
        XSToNative(value); // convert from WideString
        Result := AsDateTime; // convert to TDateTime  finally
      finally
        Free();
      end;
    end;
    
    class function TIso8601.UtcDateTimeToIso8601(const Value: TDateTime): string;
    begin
      with TXSDateTime.Create() do
      try
        AsUTCDateTime := Value;
        Result := NativeToXS; // convert to WideString
      finally
        Free();
      end;
    end;
    
    class function TIso8601.DateTimeToIso8601(const Value: TDateTime): string;
    begin
      with TXSDateTime.Create() do
      try
        AsDateTime := Value; // convert from TDateTime
        Result := NativeToXS; // convert to WideString
      finally
        Free();
      end;
    end;
    
    class function TIso8601.UtcNow: TDateTime;
    begin
      Result := ToUtc(Now);
    end;
    
    class function TIso8601.ToUtc(const Value: TDateTime): TDateTime;
    var
      Bias: TDateTime;
    begin
      Bias := TimeZoneBias;
      Result := Value + TimeZoneBias;
    end;
    
    class function TIso8601.FromUtc(const Value: TDateTime): TDateTime;
    var
      Bias: TDateTime;
    begin
      Bias := TimeZoneBias;
      Result := Value - TimeZoneBias;
    end;
    
    end.
  • 相关阅读:
    《软件测试经验与教训》—读书笔记
    【转】性能测试工程师的素质
    【转】如何成为优秀的性能测试工程师
    性能测试学习之路
    FTP 、TCP/IP、HTTP、Cookies、Session
    Loadrunner工具介绍
    tesseract-ocr图像识别技术(一)
    MongoDB 自动分片 auto sharding
    mongodb 3.0下载安装、配置及mongodb最新特性、基本命令教程详细介绍
    java使用memcached2--集群部署
  • 原文地址:https://www.cnblogs.com/starluck/p/4293062.html
Copyright © 2011-2022 走看看