“DateTime"在 VS2015 中不包含“ToShortDateString"的定义 [英] 'DateTime' does not contain a definition for 'ToShortDateString' in VS2015

查看:37
本文介绍了“DateTime"在 VS2015 中不包含“ToShortDateString"的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VS 2015 中创建通用应用程序并尝试对共享项目中的 DateTime 使用 .ToShortDateString() 方法时遇到以下问题.Visual Studio 2015 智能感知将此显示为错误,但应用程序运行良好.只是想知道,这是 VS 中的错误还是我遗漏了什么?

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?

推荐答案

UWP 应用使用 新的 CoreCLR 用于编译.CoreCLR 目前不支持 DateTime.ToShortDateString它不支持无论如何,它似乎获得了很大的吸引力.那些辅助方法不擅长本地化.

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.

您可以简单地将调用替换为 dateToDisplay.ToString("d").

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

看起来它有一些吸引力!此方法(以及其他几种方法)已重新添加到 CoreCLR.这样做是为了提高与 Xamarin 和 .Net Framework 中的 API 的一致性.您可以阅读有关此决定的更多信息 此处.

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.

这篇关于“DateTime"在 VS2015 中不包含“ToShortDateString"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆