Bug 17558 – DateTime should support custom user-provided formatting

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-06-26T11:46:00Z
Last change time
2017-06-26T12:40:21Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2017-06-26T11:46:38Z
Currently there's a collection of formatting functions, but each one follows some predefined standard, such as: - toSimpleString - toISOString - toISOExtString However if you want your own formatting, you have to do everything manually currently, which is a pain. Here's what I envision the API to be like: ------ // auto time = SysTime(...); // imagine it's 2017-02-03 14:10:50 auto formatted = time.toFormattedString("YYYY-MM-DD HH:MM"); assert(formatted == "2017-02-03 14:10"); auto formatted = time.toFormattedString("YYYY-MM HHh"); assert(formatted == "2017-02 14h"); ------ The exact formatting strings defined aren't important to me, but having the ability to output certain information I want in a certain format is important - e.g. leaving out seconds, using numbers instead of words for months, etc..
Comment #1 by dlang-bugzilla — 2017-06-26T12:40:21Z
Looks like an exact dupe! *** This issue has been marked as a duplicate of issue 13533 ***