Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'DateTime' does not contain a definition for 'ToShortDateString' in VS2015

Had the following issue when created universal app in VS 2015 and tried to use .ToShortDateString() method for DateTime in the Shared Project. Visual Studio 2015 intellisense shows this as an error, but the application runs fine. Just wondering, is this a bug in VS or am I missing something?

enter image description here

enter image description here

like image 391
Farzad Jafarizadeh Avatar asked May 17 '16 00:05

Farzad Jafarizadeh


People also ask

What is short date string?

The string returned by the ToShortDateString method is culture-sensitive. It reflects the pattern defined by the current culture's DateTimeFormatInfo. ShortDatePattern property. For example, for the en-US culture, the standard short date pattern is "M/d/yyyy"; for the de-DE culture, it is "dd.

How to use ToShortDateString in c#?

This method is used to convert the value of the current DateTime object to its equivalent short date string representation. Syntax: public string ToShortDateString (); Return Value: This method returns a string that contains the short date string representation of the current DateTime object.


1 Answers

UWP apps use the new CoreCLR for compilation. The CoreCLR does not support DateTime.ToShortDateString at this time, and it doesn't 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.

like image 51
Will Ray Avatar answered Sep 19 '22 10:09

Will Ray