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?
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.
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.
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")
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With