On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via Digitalmars-d- learn wrote: > ```D > import std.datetime : Clock, format; > import std.stdio : writeln; > > void main() > { > auto currentTime = Clock.currTime; > > auto formattedTime = currentTime.format("%Y-%m-%d %H:%M:%S"); > > writeln("Formatted Time: ", formattedTime); > } > ```
std.datetime does not currently support custom date/time formats. It only supports the ISO format, the ISO Extended format, and Boost's simple time format. // e.g. 20240118T163806.5813052 auto iso = time.toISOString(); // e.g. 2024-01-18T16:38:06.5813052 auto isoExt = time.toISOExtString(); // e.g. 2024-Jan-18 16:38:06.5813052 auto boostSimple = time.toSimpleString(); So, if you want a different format, you'll either need to make one yourself by calling the various properties on SysTime and passing them to something like std.format's format to create a string, or there are several packages on https://code.dlang.org which have functions for doing custom date/time formatting. - Jonathan M Davis