简体   繁体   中英

how to convert DateTime to a specified Format in windows phone 8

I have this date format MM/dd/yyyy. The problem is, when i convert it displays 05-12-2013.I want to display formate like 05/12/2013. How can i correctly format it to: 05/12/2013?

My c# code is

 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. 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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