Delphi
StringをUTF-8フォーマットに変換
uses Windows; function ToUTF8(s: String): String; var ws: WideString; len: Integer; begin ws := WideString(s); len := WideCharToMultiByte(CP_UTF8, 0, PWideChar(ws), -1, Nil, 0, Nil, Nil); SetLength(Result, len+1); WideCharToMultiByte(CP_UTF8, 0, PWideChar(ws), -1, PChar(Result), len, Nil, Nil); Result := PChar(Result); end;
RFC3339形式(2005-12-17T03:11:13.867+09:00)でTDateTimeをダンプ
uses Windows, DateUtils, StrUtils; function LocalDateTimeToInternetDateTime(t: TDateTime): String; var offset: TDateTime; TZI: TTimeZoneInformation; begin offset := 0; case GetTimeZoneInformation(TZI) of TIME_ZONE_ID_STANDARD: offset := (TZI.Bias + TZI.StandardBias) / 1440; TIME_ZONE_ID_DAYLIGHT: offset := (TZI.Bias + TZI.DaylightBias) / 1440; TIME_ZONE_ID_UNKNOWN: offset := TZI.Bias / 1440; else //RaiseLastWin32Error; end; t := t+offset; offset := -offset; Result := FormatDateTime('yyyy-mm-dd', t) + 'T' + FormatDateTime('hh:nn:ss.zzz', t); if (Abs(offset) >= 1/1440) then begin Result := Result+IfThen(offset>0, '+', '-') +Format('%.2d:%.2d', [HourOf(offset), MinuteOf(offset)]); end else begin Result := Result+'Z'; end; end;