Build a SysTime from a string
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 6 07:55:51 PDT 2016
On Wednesday, July 06, 2016 14:15:22 Andrea Fontana via Digitalmars-d-learn
wrote:
> Ok, I have a string like:
> 2011-03-02T15:30:00+01:00
>
> I need to convert it in a SysTime object.
>
> My problem is that from documentation I can't understand how to
> set +01:00 timezone on systime. I guess I'm missing something...
So, you want to take the string "2011-03-02T15:30:00+01:00" and create a
SysTime from it? Well, that's the extended ISO format, so just use
SysTime.fromISOExtString. e.g.
auto st = SysTime.fromISOExtString("2011-03-02T15:30:00+01:00");
You'll get a SysTime with the appropriate value for stdTime (in UTC), and
it'll have a SimpleTimeZone with a UTC offset of +1 hours. And if you want
that to then be in a different time zone, you can then convert it to other
time zones via toUTC, toLocalTime, or toOtherTZ (or by just setting its time
zone if you want to mutate it rather than getting a new value).
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list