Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #816 (closed enhancement: fixed)

Opened 9 months ago

Last modified 9 months ago

Date formatting lacks a way to return non-0-padded digits.

Reported by: darrylb Assigned to: larsivi
Priority: major Milestone: 0.99.4
Component: Core Functionality Version: 0.99.3 Triller
Keywords: Cc:

Description

(Related to Ticket 815)

In comparison with Java, one can do (with date 0001-01-01 01:01:01):

SimpleDateFormat formatter = new SimpleDateFormat("y-M-d h:m:s");
SimpleDateFormat formatter = new SimpleDateFormat("s");

And get back: 01-1-1 1:1:1, and 1, respectively. (no idea why the year is still 0 padded, but, w/e).

In C# however, according to the docs, a date format of say, "{:s}", gives back a 'sortable' date/time like: 0001-01-01T03:02:01.

However, if you want a single character, you have to use %, as in: "{:%s} to get back: 1.

I haven't actually compiled any C# to test this, just going by the docs as here: http://msdn2.microsoft.com/en-us/library/8kb3ddd4(VS.71).aspx. Copied and pasted from there:

"Displays the seconds for the specified DateTime? in the range 0-59. The second represents whole seconds passed since the last minute. If the second is a single digit (0-9), it is displayed as a single digit only.

Note that if the 's' format specifier is used alone, without other custom format strings, it is interpreted as the standard sortable date/time pattern format specifier. If the 's' format specifier is passed with other custom format specifiers or the '%' character, it is interpreted as a custom format specifier."

However, I can't find any way in Tango to do the same.

Change History

12/11/07 15:23:42 changed by kris

  • owner changed from sean to larsivi.
  • milestone set to 0.99.4.

12/17/07 14:21:21 changed by larsivi

  • status changed from new to closed.
  • resolution set to fixed.

(In [3034]) Prepending a single custom format specifier with % makes it possible for the underlying value to be printed in a non-padded fashion. Follows the .net spec in this regard. Thx darrylb. closes #816