A lot of APIs want the ISO8601 without the milliseconds like this:
Get only orders which were placed after this timestamp. Should be in YYYY-MM-ddTHH:mm:ssZ format
I guess the main "issue" is the dot after the seconds (between seconds and milliseconds), one would have to url-encode the dot (http GET speaking), right?
SDateFormat: string = 'yyyy''-''mm''-''dd''T''hh'':''nn'':''ss''.''zzz''Z'''; { Do not localize }
I am unable to lose the milliseconds.
DateToISO8601(TTimeZone.Local.ToUniversalTime(RecodeMilliSecond(now, 0), false), true)
This is my approach at the moment:
var
utc: TDateTime;
...
utc := TTimeZone.Local.ToUniversalTime(now);
utc := RecodeMilliSecond(utc, 0);
... Format('/orders?storefront=de&ts_created_from_iso=%sT%sZ', [FormatDateTime('yyyy-mm-dd', utc), FormatDateTime('hh:nn:ss', utc)])
Any other ideas?
If I'm understanding your question correctly, you want to know how to make
DateToISO8601()
not output milliseconds, correct? The answer is, you can't. But, it would be very easy to strip off the milliseconds after the fact usingSystem.Delete()
orTStringHelper.Remove()
since you know the exact offset and length of the milliseconds in the resulting string.Otherwise, just stick with your manually approach. However, you don't need
RecodeMilliseconds()
, and only 1 call toFormatDateTime()
will suffice: