Bug 29945 - DateTimeOffset.ToString(format) returns wrong output for some format values
Summary: DateTimeOffset.ToString(format) returns wrong output for some format values
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.20.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2015-05-11 13:07 UTC by Michael Duerinckx
Modified: 2015-05-12 04:21 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Versions of Visual Studio and Xamarin from Help > About > Copy Info in VS (1.55 KB, text/plain)
2015-05-11 13:07 UTC, Michael Duerinckx

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Michael Duerinckx 2015-05-11 13:07:55 UTC
Created attachment 11157 [details]
Versions of Visual Studio and Xamarin from Help > About > Copy Info in VS

To reproduce:

`date` is an instance of DateTimeOffset. 
C# code:


Expected return value:

"1" - "31" - according to "Custom Date and Time Format Strings": https://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx

Actual return value:

"5/11/2015" - or any string of the format "month/day of month/year"

Now, the interesting part is that this only appears to happen (from what I've found) with format strings that consist of the letter d, singular or repeated, with nothing else in the format string. Here's another test case that did return the expected result (and which I am using as a workaround):

C# code:

date.ToString("d ");

Expected return value:

"1 " - "31 "

Actual return value:
"1 " - "31 "

In my cases I've reproduced this for the format strings "d" and "dddd".

Attached are the relevant versions of my setup.
Comment 1 Atsushi Eno 2015-05-12 02:23:44 UTC
You are misunderstanding the API. The format string for DateTimeOffset.ToString(format) is this.
Comment 2 Michael Duerinckx 2015-05-12 03:17:43 UTC
My sincerest apologies for wasting your time looking into this. I now see that the article you linked is even referred to in first paragraph of the one I linked in my original report. 

Thank you for pointing this out to me; I'll read more carefully before jumping to conclusions next time.
Comment 3 Atsushi Eno 2015-05-12 04:21:44 UTC
No worries, you'll end up to like these date/time types that offer several levels of formats from easy-to-use to highly-customizible ones :-)