开发者

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

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

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

精彩评论

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