Convert String to Date and Add ±N Hours

Vahid sabeti.ltd at gmail.com
Mon Nov 6 17:33:06 UTC 2023


On Saturday, 4 November 2023 at 19:19:43 UTC, Jonathan M Davis 
wrote:
> On Saturday, November 4, 2023 12:11:53 PM MDT Vahid via 
> Digitalmars-d-learn wrote:
>> [...]
>
> If you're using D's standard library, you would need to replace 
> the space
> with a T so that the time format was ISO extended. Then you can 
> use
> DateTime.fromISOEXtString() in std.datetim.date to get a 
> DateTime. You can
> then add a duration to the DateTime to change its value - e.g. 
> using
> hours(2) (or dur!"hours"(2) for the generic version). Then if 
> you want
> a string again, toISOExtString will convert the DateTime to the 
> ISO extended
> format, and if you want a space instead of a T, then just 
> replace the T with
> a space in the string. E.G.
>
> [...]

Thank you. It works very well.


More information about the Digitalmars-d-learn mailing list