如何将MySQL中的持续时间值存储为TIME数据类型?

我需要以分钟/秒为单位存储歌曲持续时间,我需要使用TIME,但是当我编写INSERT语句时,我将如何引用某个持续时间?我在表中的数据类型已经是TIME,我应该STR_TO_DATE字符串值“4:29”吗?

解决方法:

首先,看看这里:http://dev.mysql.com/doc/refman/5.0/en/time.html

Be careful about assigning abbreviated values to a TIME column. MySQL
interprets abbreviated TIME values with colons as time of the day.
That is, ’11:12′ means ’11:12:00′, not ’00:11:12′. MySQL interprets
abbreviated values without colons using the assumption that the two
rightmost digits represent seconds (that is, as elapsed time rather
than as time of day). For example, you might think of ‘1112’ and 1112
as meaning ’11:12:00′ (12 minutes after 11 o’clock), but MySQL
interprets them as ’00:11:12′ (11 minutes, 12 seconds). Similarly,
’12’ and 12 are interpreted as ’00:00:12′.

所以,如果你想要插入持续时间= 05:55的歌曲,那就写下:

insert into songs (duration) values('0555');
上一篇:在Java 8 / jsr310中格式化持续时间


下一篇:如何在Java中存储花费的时间或总持续时间?