[fpc-pascal] JSON dates

Graeme Geldenhuys graeme at geldenhuys.co.uk
Thu Feb 21 12:18:16 CET 2013

On 2013-02-21 09:59, Reinier Olislagers wrote:
> Noticed that Firefox gives this:
> new Date().toJSON();
> /*
> 2013-02-21T09:47:42.467Z
> */
> which looks like an ISO date to me.

Yes, that is the ISO 8601 format, and the only sane format you should
use. Even in my database application, my dates are stored as text fields
using the ISO 8601 date/time format, instead of db server Timestamp
fields (which could cause confusion too, depending on server locale

> Is this ISO 8601 format currently the most widely used? It seems the
> most sane to me.

Yes, that is the safest and most understood format.

In the tiOPF project I created a couple of methods (and unit tested
them) to do conversion between string format and TDateTime format. You
are welcome to use them for your purpose.

----------------[ Core/tiUtils.pas ]--------------------
  function tiDateTimeAsIntlDateStor(const ADateTime: TDateTime): string;
  function tiDateTimeAsIntlDateDisp(const ADateTime: TDateTime): string;
  function tiDateAsIntlDateDisp(const ADateTime: TDateTime): string;
  function tiIntlDateStorAsDateTime(const AValue: string): TDateTime;
  function tiIntlDateDispAsDateTime(const AValue: string): TDateTime;

Code can be found here...


Also, here is a summary of ISO 8601:

  - Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal

More information about the fpc-pascal mailing list