Sample code to format date in MM-dd-yy format [C#] :
using System;
using System.Globalization;
public class DateFormatSample
{
public static void Main()
{
string dateToFormat = "10-29-11";
string strFormatPattern = "MM-dd-yy";
DateTime formattedDate;
DateTime.TryParseExact(dateToFormat, strFormatPattern, null,
DateTimeStyles.None, out formattedDate);
Console.WriteLine("Date '{0}' Formatted to {1:d}.", dateToFormat, formattedDate);
}
}
// output:
// Date '12-30-11' Formatted to 12/30/2011.
Here MM displays in format 01 to 12, dd represents Day of the month with range from 01 to 31 and yy is year from 00 to 99.
0 Comments :
Post a Comment