开发者

Returning Just Time (in Military) from DB in ASP.NET/VB.NET

开发者 https://www.devze.com 2023-02-15 03:35 出处:网络
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:

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消