I know that I could use a format string, but I don\'t want to lose the culture specific representation of the date/time format. E.g.
5/4/2011 | 2:06 PM | ...>
I wrote a method to do that kind of transformations :
///
/// Transform DateTime into short specified format
///
/// string : input DateTime
///
/// string - optional : ouput format - default "d"
///
public static string ConvertDateTimeToShortDate(string strDateTime, CultureInfo cultureInfo, string strFormat="d")
{
var dateTime = DateTime.MinValue;
return DateTime.TryParse(strDateTime, out dateTime) ? dateTime.ToString(strFormat, cultureInfo) : strDateTime;
}
To call it, for time format :
DateTimeTools.ConvertDateTimeToShortDate(DateTime.Today.ToString(),
CultureInfo.InvariantCulture,"t");
Hope it can help u