c# – DateTime does not contain a definition for ToShortDateString in VS2015

c# – DateTime does not contain a definition for ToShortDateString in VS2015

UWP apps use the new CoreCLR for compilation. The CoreCLR does not support DateTime.ToShortDateString at this time, and it doesnt seem to be getting much traction anyways. Those helper methods are bad at localization.

You can simply replace the call with dateToDisplay.ToString(d).

Update

Looks like it got some traction! This method (along with several others) was added back into the CoreCLR. This move was done to improve parity with the APIs in Xamarin and the .Net Framework. You can read more about this decision here.

Change the code to:

var test = dateToDisplay.Value.toShortDateString();

c# – DateTime does not contain a definition for ToShortDateString in VS2015

This is only an error because code analysis is told to treat this as an error. You can change this to a warning or ignore completely, but it is recommended to improve your code.

Leave a Reply

Your email address will not be published. Required fields are marked *