11.2.3 The TIME Type时间类型

MySQL retrieves and displays TIME values in 'hh:mm:ss' format (or 'hhh:mm:ss' format for large hours values). MySQL以'hh:mm:ss'格式显示TIME值(但是大小时值改用'hhh:mm:ss'格式)。TIME values may range from '-838:59:59' to '838:59:59'. TIME值的范围可以是'-838:59:59''838:59:59'The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).小时部分可能非常大,因为TIME类型不仅可以用来表示一天中的某个时间(必须小于24小时),还可以表示经过的时间或两个事件之间的时间间隔(可能远远大于24小时,甚至是负数)。

MySQL recognizes TIME values in several formats, some of which can include a trailing fractional seconds part in up to microseconds (6 digits) precision. MySQL可以识别多种格式的TIME值,其中一些格式可以包含精度高达微秒(6位数)的小数部分。See Section 9.1.3, “Date and Time Literals”. 请参阅第9.1.3节,“日期和时间文字”For information about fractional seconds support in MySQL, see Section 11.2.6, “Fractional Seconds in Time Values”. 有关MySQL中分数秒支持的信息,请参阅第11.2.6节,“时间值中的分数秒”In particular, any fractional part in a value inserted into a TIME column is stored rather than discarded. 特别地,插入到TIME列中的值中的任何小数部分都被存储而不是丢弃。With the fractional part included, the range for TIME values is '-838:59:59.000000' to '838:59:59.000000'.如果包含小数部分,则TIME值的范围为'-838:59:59.000000''838:59:59.000000'

Be careful about assigning abbreviated values to a TIME column. TIME列指定缩写值时要小心。MySQL interprets abbreviated TIME values with colons as time of the day. MySQL将带有冒号的缩写TIME值解释为一天中的时间。That is, '11:12' means '11:12:00', not '00:11:12'. 也就是说,'11:12'的意思是'11:12:00',而不是'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). MySQL使用两个最右边的数字表示秒(即,作为经过的时间而不是一天中的时间)的假设来解释不带冒号的缩写值。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). 例如,您可能认为'1112'1112的意思是'11:12:00'(11点后12分钟),但MySQL将其解释为'00:11:12'(11分钟,12秒)。Similarly, '12' and 12 are interpreted as '00:00:12'.类似地,'12'12被解释为'00:00:12'

The only delimiter recognized between a time part and a fractional seconds part is the decimal point.时间部分和小数秒部分之间唯一可识别的分隔符是小数点。

By default, values that lie outside the TIME range but are otherwise valid are clipped to the closest endpoint of the range. 默认情况下,位于TIME范围之外但在其他方面有效的值将被剪裁到该范围的最近端点。For example, '-850:00:00' and '850:00:00' are converted to '-838:59:59' and '838:59:59'. 例如,'-850:00:00''850:00:00'将转换为'-838:59:59''838:59:59'Invalid TIME values are converted to '00:00:00'. 无效的TIME值转换为'00:00:00'Note that because '00:00:00' is itself a valid TIME value, there is no way to tell, from a value of '00:00:00' stored in a table, whether the original value was specified as '00:00:00' or whether it was invalid.请注意,由于'00:00:00'本身是有效的时间值,因此无法从表中存储的'00:00:00'值判断原始值是指定为'00:00:00'还是无效。

For more restrictive treatment of invalid TIME values, enable strict SQL mode to cause errors to occur. 要对无效TIME值进行更严格的处理,请启用严格SQL模式以导致错误发生。See Section 5.1.11, “Server SQL Modes”.请参阅第5.1.11节“服务器SQL模式”