I'm saving military time into the database. Then I need to pull this data back out of the database. To get just the time without the date I can do this:
String.Format("{0:T}", pullsaved.First.timeValue)
But this returns a six digit time, e.g. 100000 (HHmmss). But开发者_开发技巧 I want it to return just HHmm (1000). I tried the following, but it didn't work...any ideas?
DateTime.ParseExact(String.Format("{0:T}", pullsaved.First.timeValue), "HHmm", CultureInfo.InvariantCulture)
String.Format("{0:HHmm}", pullsaved.First.timeValue)
or
pullsaved.First.timeValue.ToString("HHmm")
Easiest way is:
DateTime dt = someDate;
string formattedDate = dt.ToString("HHmm");
精彩评论