digitalmars.D.learn - Formatting dates
- Chris Wright (4/4) Nov 28 2015 Is there a way to format a DateTime struct similar to strftime(3)? None
- Jonathan M Davis via Digitalmars-d-learn (12/16) Nov 28 2015 Unfortunately, std.datetime does not currently support custom formatting
Is there a way to format a DateTime struct similar to strftime(3)? None is documented, and none is immediately obvious in the source code. Or is the recommended way to convert a DateTime to a Unix timestamp and then use strftime?
Nov 28 2015
On Saturday, November 28, 2015 18:10:49 Chris Wright via Digitalmars-d-learn wrote:Is there a way to format a DateTime struct similar to strftime(3)? None is documented, and none is immediately obvious in the source code. Or is the recommended way to convert a DateTime to a Unix timestamp and then use strftime?Unfortunately, std.datetime does not currently support custom formatting for any of the time point types (it's on my todo list, and I should have finished years ago but haven't). In most cases, toISOExtString is what folks should be using, but at this point, if you want a format other than those provided, you're going to need to do it on your own somehow. There isn't really a recommended way to do it. However, strftime would be one option, and it takes a tm*, which has the time all split out like DateTime does, so that would mean either setting all of its fields yourself, or converting the DateTime to a SysTime and using its toTM() function to convert it a tm. Converting it to a SysTime would probably be easier. - Jonathan M Davis
Nov 28 2015