Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
July 06, 2016 Build a SysTime from a string | ||||
---|---|---|---|---|
| ||||
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... Andrea |
July 06, 2016 Re: Build a SysTime from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Wednesday, 6 July 2016 at 14:15:22 UTC, Andrea Fontana wrote:
> My problem is that from documentation I can't understand how to set +01:00 timezone on systime. I guess I'm missing something...
As far as I know, you can't do that.
Quote from the documentation:
"""
Unlike DateTime, the time zone is an integral part of SysTime (though for local time applications, time zones can
"""
It does make sense, right? SysTime is object representing your system's time, and naturally it already has timezone set to the right (system) value.
|
July 06, 2016 Re: Build a SysTime from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dejan Lekic | On Wednesday, 6 July 2016 at 14:19:56 UTC, Dejan Lekic wrote:
> On Wednesday, 6 July 2016 at 14:15:22 UTC, Andrea Fontana wrote:
>> My problem is that from documentation I can't understand how to set +01:00 timezone on systime. I guess I'm missing something...
>
> As far as I know, you can't do that.
>
> Quote from the documentation:
> """
> Unlike DateTime, the time zone is an integral part of SysTime (though for local time applications, time zones can
> """
>
> It does make sense, right? SysTime is object representing your system's time, and naturally it already has timezone set to the right (system) value.
But SysTime has a c-tor that accepts a TimeZone, how can I set that?
Anyway, If i'm not wrong, it's the only object with TimeZone support, isn't it?
|
July 06, 2016 Re: Build a SysTime from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | 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 |
July 06, 2016 Re: Build a SysTime from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wednesday, 6 July 2016 at 14:55:51 UTC, Jonathan M Davis wrote:
> auto st = SysTime.fromISOExtString("2011-03-02T15:30:00+01:00");
That's perfect. I didn't notice that static method. My fault!
|
July 06, 2016 Re: Build a SysTime from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Wednesday, 6 July 2016 at 15:38:00 UTC, Andrea Fontana wrote: > On Wednesday, 6 July 2016 at 14:55:51 UTC, Jonathan M Davis wrote: >> auto st = SysTime.fromISOExtString("2011-03-02T15:30:00+01:00"); > > That's perfect. I didn't notice that static method. My fault! Also, if you need to parse other formats: https://github.com/JackStouffer/date-parser#simple-example |
Copyright © 1999-2021 by the D Language Foundation