-1

我正面临这个问题。例如,当我从网站结束时间时,我总是得到 0:00h 或 0:30h。这在技术上是在当前日期的开始。但是对于人类来说是在当前日期的末尾。

我需要直接从数据库中对 0:00 到 6:00 进行排序,而不是在一天结束时进行排序。

我正在使用 java、hibernate 标准、mysql datetime。谢谢大家!

4

1 回答 1

1

You can get your dates and times ordered correctly by using MySql DATETIME data types throughout your application. The Java equivalent class is util.Date.

According to computer and telecommunications industry standards, the first millisecond of each calendar day has the time 00:00.000. So, if you add ten seconds to 23:59:51.000 you get 00:00:01.000 on the next day.

It sounds like your business has a different, non-standard, rule for describing the beginning and ending of each day, to use for this particular display. That's fine. But you need to enumerate this rule very precisely indeed. Midnight matters in many fields of human endeavor!

Let's say your rule is that a day's information runs from [01:00:00 to 01:00:00) the next day.

Then you can select yesterday's records in a MySQL query like this.

WHERE `timestamp` >= CURDATE() - INTERVAL 1 DAY + INTERVAL 1 HOUR
  AND `timestamp` < CURDATE() + INTERVAL 1 HOUR
  ...
ORDER BY `timestamp`

This will display your stuff in the right order. It won't display the time 24:01, but it will place 00:01 after 23:59.

于 2013-06-27T18:47:17.680 回答