HTML input + formatting value to date
I have date as a string 16/11/2010 12:00:00 AM
for example which I am inputting in
<input type="text" value="<%: Object.Instance.SomeDateAsString %>" />
Note: this can either be empty string or in 16/11/2010 12:00:00 AM
format only.
How can I display it it nicely to t开发者_StackOverflow社区he user as a 16-Nov-2010
?
<input type="text" value="<%: Object.Instance.GetFormattedDateString() %>" />
then on your object:
public String GetFormattedDateString()
{
String returnString = String.Empty;
DateTime parsedDateTime;
DateTime.TryParse(this.SomeDateAsString, parsedDateTime);
if (parsedDateTime != DateTime.MinValue)
{
returnString = String.Format("{0:dd-MMM-yyyy}", parsedDateTime);
}
return returnString;
}
See here for many patterns of the DateTime.ToString() Patterns.
For your specific format you need: DateTime.ToString("dd-MMM-yyyy")
精彩评论