www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Build a SysTime from a string

reply Andrea Fontana <nospam example.com> writes:
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
next sibling parent reply Dejan Lekic <dejan.lekic gmail.com> writes:
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
parent Andrea Fontana <nospam example.com> writes:
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?
Jul 06 2016
prev sibling parent reply Jonathan M Davis via Digitalmars-d-learn writes:
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
parent reply Andrea Fontana <nospam example.com> writes:
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
parent Jack Stouffer <jack jackstouffer.com> writes:
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
Jul 06 2016