VB.NET 如何将字符串转换为时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28914221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET how to convert a string into time
提问by aLeXaNdRa08
Ive been having some trouble with this for a while. I want to be able to retrieve values of time stored in my database (as type time). I've tried:
我在这方面遇到了一些麻烦。我希望能够检索存储在我的数据库中的时间值(作为时间类型)。我试过了:
reader.getDateTime("open_hours")
I just get an error. I've also tried converting the string into time but i can only convert it into datetime, meaning that i have the date as well as the time. How can i get just the time (in 24 hour format)?
我只是收到一个错误。我也尝试将字符串转换为时间,但我只能将其转换为日期时间,这意味着我有日期和时间。我怎样才能得到时间(24 小时制)?
回答by Pradnya Bolli
you can use this link
你可以使用这个链接
for example:-
例如:-
Dim strTime As String = "3:00 PM"
' Convert to datetime
Dim dtTime As DateTime = Convert.ToDateTime(strTime)
' Display in 24hr format
Response.Write(dtTime.ToString("HH:mm"))
example2:-
示例2:-
string militaryTime;
string originalTime = "3:11 PM";
DateTime dt;
if (DateTime.TryParse(originalTime, out dt))
militaryTime = dt.ToString("HH:mm");

