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.
精彩评论