std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Mar 9 16:08:31 UTC 2020


On Sunday, March 8, 2020 11:19:33 PM MDT tchaloupka via Digitalmars-d-learn 
wrote:
> On Sunday, 8 March 2020 at 17:28:33 UTC, Robert M. Münch wrote:
> > On 2020-03-07 12:10:27 +0000, Jonathan M Davis said:
> >
> > DateTime dt =
> > DateTime.fromISOExtString(split("2018-11-06T16:52:03+01:00",
> > regex("\\+"))[0]);
> >
> > IMO such a string should be feedable directly to the function.
>
> You just need to use SysTime.fromISO*String functions for that,
> as DateTime does't work with timezones, SysTime do.

Exactly. DateTime does not support timezones or fractional seconds. If you
want that, then use SysTime. And if you want to get a DateTime from a string
such as "2018-11-06T16:52:03+01:00", then just use SysTime's
fromISOExtString and convert the result to DateTime. e.g.

auto dt =
    cast(DateTime)SysTime.fromISOExtString("2018-11-06T16:52:03+01:00"");

The documentation for the from*String functions say what they support.

- Jonathan M Davis






More information about the Digitalmars-d-learn mailing list