如何使用经典ASP将TIME格式化为HH:MM AM / PM格式?

时间:2021-08-08 05:02:59

I am going nuts with this one. I have a mySQL table with a field of TIME type. I want to display a time such as 09:00 PM, and not 09:00:00 PM. I got this to work but think there must be a better way -

我对此很疯狂。我有一个带有TIME类型字段的mySQL表。我想显示一个时间,如09:00 PM,而不是09:00:00 PM。我让这个工作,但认为必须有一个更好的方法 -

monday = FormatDateTime(rs("d1s"), vbLongTime) response.write replace(monday,":00 AM"," AM")

monday = FormatDateTime(rs(“d1s”),vbLongTime)response.write replace(星期一,“:00 AM”,“AM”)

I've read through a lot of resources but can't put my finger on how best to do this. Any help would be appreciated.

我已经阅读了很多资源,但无法确定如何做到最好。任何帮助,将不胜感激。

Also, if there is a way to eliminate the first digit if a 0, such as not 09:00 AM but 9:00 AM

此外,如果有一种方法可以消除第一个数字,如果是0,例如不是09:00 AM而是9:00 AM

1 个解决方案

#1


2  

since you are using MySQL, use DATE_FORMAT in your SELECT statement,

因为您使用的是MySQL,所以在SELECT语句中使用DATE_FORMAT,

SELECT DATE_FORMAT(ColumnName, '%l:%i %p')

See SQLFiddle Demo

#1


2  

since you are using MySQL, use DATE_FORMAT in your SELECT statement,

因为您使用的是MySQL,所以在SELECT语句中使用DATE_FORMAT,

SELECT DATE_FORMAT(ColumnName, '%l:%i %p')

See SQLFiddle Demo