开发者

Displaying and Saving "time" datatype from SQL with C#?

How do I properly displays the "time" datatype of MS SQL to ASP.NET MVC page? When I get the column to my class (the property in my class in of type DateTime), I call the "ToShorTimeString()" meth开发者_JS百科od but then that would displays something like this: "1/1/0001 12:00:00 AM"

I need it to be able to display as, i.e. "11:00 AM", and when making update, able to save the correct value back to the database as Time datatype.


myDate.ToString("hh:mm tt");


Timespan ts = TimeSpan.Parse("15:00:00.0000000");
DateTime dt = new DateTime(ts.Ticks);
Response.Write(dt.ToShortTimeString());

here you go.

output: 3:00 PM


Well I've changed that SQL column to use DateTime instead :) Why not making it easier! Thanks all for the responses.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜