在 JavaScript 中比较 MySQL 日期
这只是一个健全性检查,但在你们都跳上“向下”按钮之前我已经完成了几个测试用例 =]
我只想检查比较 MySQL 数据库中格式 YYYY-MM-DD 的日期JavaScript 中的 HH:MM:SS
将正常工作。不幸的是,我无法编辑查询以返回 Unix 时间戳。
示例:
console.log('2010-05-22 00:54:12' > '2010-05-21 11:44:32');
我的所有测试用例似乎都表明它工作正常,但我只需要确认一下。
也许我的谷歌能力很弱,但我在网上找不到任何相关信息。有谁确切知道吗?
This is just a sanity check, but I've done several test cases before you all jump on the "down" button =]
I just want to check that comparing dates from a MySQL database in the format YYYY-MM-DD HH:MM:SS
in JavaScript will work correctly. Unfortunately, I can't edit the query to return a Unix timestamp.
Example:
console.log('2010-05-22 00:54:12' > '2010-05-21 11:44:32');
All my test cases seem to suggest it works fine, but I just need to make sure.
Maybe my Google-fu is weak, but I can't find anything about it online. Does anyone know for sure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,我确信他们选择这种格式的原因之一是这样您可以对它们进行标准字符串比较。
因为值的顺序是从最重要到最不重要,所以只要满足以下条件,就可以正常工作:
但请注意,除非您对特定时区(例如 GMT)进行标准化,否则这只能准确比较单个时区的日期。
Yes, I'm sure one reason they chose such a format was so you could do a standard string comparison on them.
Because the order of values is most-significant to least-significant, this will work perfectly fine as long as:
However do note that unless you standardize on a particular time zone (GMT for example), this will only accurately compare dates in a single time zone.