digitalmars.D.learn - Build a SysTime from a string
- Andrea Fontana (6/6) Jul 06 2016 Ok, I have a string like:
- Dejan Lekic (10/12) Jul 06 2016 As far as I know, you can't do that.
- Andrea Fontana (5/18) Jul 06 2016 But SysTime has a c-tor that accepts a TimeZone, how can I set
- Jonathan M Davis via Digitalmars-d-learn (12/17) Jul 06 2016 So, you want to take the string "2011-03-02T15:30:00+01:00" and create a
- Andrea Fontana (2/3) Jul 06 2016 That's perfect. I didn't notice that static method. My fault!
- Jack Stouffer (3/8) Jul 06 2016 Also, if you need to parse other formats:
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
Jul 06 2016
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.
Jul 06 2016
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: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?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.
Jul 06 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
Jul 06 2016
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!
Jul 06 2016
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:Also, if you need to parse other formats: https://github.com/JackStouffer/date-parser#simple-exampleauto st = SysTime.fromISOExtString("2011-03-02T15:30:00+01:00");That's perfect. I didn't notice that static method. My fault!
Jul 06 2016