Re: Formatted date
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!
Re: Formatted date
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
Re: Formatted date
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.
Re: Formatted date
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
Re: Formatted date
On 03/11/2011 23:58, Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? snip Yes. See the datetime stuff in http://pr.stewartsplace.org.uk/d/sutil/ Stewart.
Re: Formatted date
On 04/11/2011 00:51, Jonathan M Davis wrote: On Thursday, November 03, 2011 16:58 Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? Something like strftime in python; http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior Not currently. snip I could've sworn it was you I was talking to about the stuff in my library before. Are you an imposter? Stewart.
Re: Formatted date
On Thursday, December 01, 2011 11:28:39 Stewart Gordon wrote: On 04/11/2011 00:51, Jonathan M Davis wrote: On Thursday, November 03, 2011 16:58 Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? Something like strftime in python; http://docs.python.org/library/datetime.html#strftime-and-strptime-beh avior Not currently. snip I could've sworn it was you I was talking to about the stuff in my library before. Are you an imposter? Why would I be an imposter? - Jonathan M Davis
Re: Formatted date
On Thursday, December 01, 2011 22:33:00 Stewart Gordon wrote: On 01/12/2011 16:44, Jonathan M Davis wrote: On Thursday, December 01, 2011 11:28:39 Stewart Gordon wrote: snip I could've sworn it was you I was talking to about the stuff in my library before. Are you an imposter? Why would I be an imposter? If you weren't, you would already know about my library and not be posting under the premise that it doesn't exist. There's a halfway decent chance that I posted in this thread prior to reading anything about your library or before I looked at it at all. - Jonathan M Davis
Re: Formatted date
On 01/12/2011 22:57, Jonathan M Davis wrote: snip There's a halfway decent chance that I posted in this thread prior to reading anything about your library or before I looked at it at all. And both Lishaak's and your computers had their clocks set several days fast at the time? Stewart.
Re: Formatted date
On Friday, December 02, 2011 00:00:09 Stewart Gordon wrote: On 01/12/2011 22:57, Jonathan M Davis wrote: snip There's a halfway decent chance that I posted in this thread prior to reading anything about your library or before I looked at it at all. And both Lishaak's and your computers had their clocks set several days fast at the time? I have no idea when the discussion on your library was in d-announce. I'd have to go digging through the archives. I don't know what the exact situation was when I answered the OP's question in this thread. It was a month ago. - Jonathan M Davis
Re: Formatted date
Oh, ok, thanks for your answer. 2011/11/4 Jonathan M Davis jmdavisp...@gmx.com: On Thursday, November 03, 2011 16:58 Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? Something like strftime in python; http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior Not currently. SysTime (and the other time point types in std.datetime) have functions for converting them to specific ISO standards but not custom formatting strings. That's in the works but hasn't been completed yet. In the meantime, you can get a time_t from a SysTime using its unixTime property and pass that to C's strftime (though be warned that it risks being an hour off on Windows, since for some bizarre reason Windows applies DST to UTC such that time_t on Windows isn't actually guaranteed to always be the number of seconds since midnight January 1st, 1970 in UTC). Another alternative is that someone ported the deprecated std.dateparse (which worked with the deprecated and very broken std.date) to use SysTime, and you can use that: https://gist.github.com/1283011 toCustomString will be added to SysTime and the other time point types in std.datetime, but its design hasn't been completed sorted out yet, let alone fully implemented, so it's in the works, but it could be a little while before it makes it into Phobos. - Jonathan M Davis
Re: Formatted date
On Thursday, November 03, 2011 16:58 Lishaak Bystroushaak wrote: Hello. Is there any way how to format date with formating strings? Something like strftime in python; http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior Not currently. SysTime (and the other time point types in std.datetime) have functions for converting them to specific ISO standards but not custom formatting strings. That's in the works but hasn't been completed yet. In the meantime, you can get a time_t from a SysTime using its unixTime property and pass that to C's strftime (though be warned that it risks being an hour off on Windows, since for some bizarre reason Windows applies DST to UTC such that time_t on Windows isn't actually guaranteed to always be the number of seconds since midnight January 1st, 1970 in UTC). Another alternative is that someone ported the deprecated std.dateparse (which worked with the deprecated and very broken std.date) to use SysTime, and you can use that: https://gist.github.com/1283011 toCustomString will be added to SysTime and the other time point types in std.datetime, but its design hasn't been completed sorted out yet, let alone fully implemented, so it's in the works, but it could be a little while before it makes it into Phobos. - Jonathan M Davis