www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Formatted date

reply Alexander Zhirov <azhirov1991 gmail.com> writes:
Tell me, how can I use such a date conversion mechanism? I didn't 
find 
[something](https://www.php.net/manual/en/datetime.format.php) 
similar on the forum.

Convert date from received time

```
Clock.currTime().toSimpleString()
```

So that i can get a more readable look:

`2023-Mar-22 16:53:42.2507395` => `2023.03.22 16:53:42`
Mar 22 2023
next sibling parent Anonymouse <zorael gmail.com> writes:
On Wednesday, 22 March 2023 at 14:02:53 UTC, Alexander Zhirov 
wrote:
 So that i can get a more readable look:

 `2023-Mar-22 16:53:42.2507395` => `2023.03.22 16:53:42`
Maybe there's a better way but I just do this. ``` import std; void main() { const now = Clock.currTime(); enum pattern = "%d.%02d.%02d %02d:%02d:%02d"; writefln(pattern, now.year, now.month, now.day, now.hour, now.minute, now.second); } ``` https://run.dlang.io/is/mhvzN2
Mar 22 2023
prev sibling next sibling parent Anonymouse <zorael gmail.com> writes:
On Wednesday, 22 March 2023 at 14:02:53 UTC, Alexander Zhirov 
wrote:
 Convert date from received time

 ```
 Clock.currTime().toSimpleString()
 ```
I missed the part about receiving the time, so ignore my previous post.
Mar 22 2023
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 3/22/23 10:02 AM, Alexander Zhirov wrote:
 Tell me, how can I use such a date conversion mechanism? I didn't find 
 [something](https://www.php.net/manual/en/datetime.format.php) similar 
 on the forum.
 
 Convert date from received time
 
 ```
 Clock.currTime().toSimpleString()
 ```
 
 So that i can get a more readable look:
 
 `2023-Mar-22 16:53:42.2507395` => `2023.03.22 16:53:42`
D's datetime intentionally does not tackle formatting -- it's a huge undertaking. There is an option on code.dlang.org: https://code.dlang.org/packages/datefmt -Steve
Mar 22 2023
parent Alexander Zhirov <azhirov1991 gmail.com> writes:
On Wednesday, 22 March 2023 at 17:53:39 UTC, Steven Schveighoffer 
wrote:
 D's datetime intentionally does not tackle formatting -- it's a 
 huge undertaking.

 There is an option on code.dlang.org: 
 https://code.dlang.org/packages/datefmt

 -Steve
I'll try it tomorrow, thanks!
Mar 22 2023