Date formatting from user input
Hai i am getting a date input(Not the DateTime.Now) from the user and i want that to transform and show in a Date format. E.g: in the XAML, will be specified and i want that to be shown as "PrintedOn - October 24,200开发者_运维问答8" .The string formatting is string.format("{0} - {1}",userText, userDate). Where am i going wrong?How can i convert the UserDate to the formatting i need. Please pecify the code. Thanks
Use this :
String.Format("{0} - {1}", userText, Date.Parse(userDate).ToString("MMMM dd,yyyy"))
where userDate is currently your date as an unspecified format in a string from the XAML. If you know the format it's arriving in, use ParseExact instead.
From your code sample, I assume this is C# or VB.NET.
String.Format("{0} - {1}", userText, userDate.ToString("D"))
does something along those lines, and gives you a string in the current locale as a bonus. See the possible format strings for more info.
if you have a date from the user:
just use DateTime.ToString()
If you need to get a date from a string, just use
DateTime. Parse(datestring)
精彩评论