www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Formatting dates in std.datetime?

reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
Is there a way to format std.datetime.Date objects with a custom format
string? In particular, I'd like to reuse month short names defined in
std.datetime, but it appears that the names are private. I'd really
rather not duplicate them by hand, if there's a way to get them.

Alternatively, if there's a date formatting function that lets you use
strftime-like format strings, that would work too.


T

-- 
Век живи - век учись. А дураком помрёшь.
Apr 20 2012
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 20/04/2012 21:29, H. S. Teoh wrote:
 Is there a way to format std.datetime.Date objects with a custom format
 string?
My utility library has a datetime module with a custom formatting facility. http://pr.stewartsplace.org.uk/d/sutil/ The format string scheme is one of my own design, using repeated-letter format specifiers similar to those found in some other schemes, and designed to be logical, natural-looking, extensible and easy to remember. It doesn't currently have functions to convert between its types and those in std.datetime, but it's straightforward to construct a DateTimeComponents from a std.datetime.Date structure and then call its format method, if you still want to use the std.datetime API and just use my library for formatting.
 In particular, I'd like to reuse month short names defined in
 std.datetime, but it appears that the names are private. I'd really
 rather not duplicate them by hand, if there's a way to get them.
<snip> My library has these arrays public. But I agree that it was somewhat gratuitous to make them private in std.datetime. Stewart.
Apr 21 2012