简体   繁体   English

如何在Windows Phone 8中将DateTime转换为指定的格式

[英]how to convert DateTime to a specified Format in windows phone 8

I have this date format MM/dd/yyyy. 我的日期格式为MM / dd / yyyy。 The problem is, when i convert it displays 05-12-2013.I want to display formate like 05/12/2013. 问题是,当我转换时它显示05-12-2013。我想显示像2013年5月12日的甲酸盐。 How can i correctly format it to: 05/12/2013? 如何正确将其格式化为:2013年5月12日?

My c# code is 我的C#代码是

 DateTime dt1 = (DateTime)obj["FromDate"];
 DateTime dtlocal1 = dt1.ToLocalTime();
 tbFromDate.Text = dtlocal1.ToString("MM/dd/yyyy");

When you use a forward slash character ( / ), that tells .Net to use the date separator that is specific to the current culture. 当您使用正斜杠字符( / )时,它将告诉.Net使用特定于当前区域性的日期分隔符。 Read here . 在这里阅读

You can use the invariant culture, where the separator is always a forward slash: 您可以使用不变区域性,其中分隔符始终为正斜杠:

dt.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)

Alternatively, you can specify in the format string to specifically use the forward slash character instead of the culture-specific date separator: 或者,您可以在格式字符串中指定专门使用正斜杠字符,而不是区域性特定的日期分隔符:

dt.ToString("MM'/'dd'/'yyyy")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM