MySQL:最好的使用,Unix TimeStamp或DATETIME [英] MySQL: What's the best to use, Unix TimeStamp Or DATETIME

查看:188
本文介绍了MySQL:最好的使用,Unix TimeStamp或DATETIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能很多编程者想提出这个问题。这是MySQL时间格式中每一种的冒险。你应该在你的应用程序中使用哪一个。



对我来说,我使用Unix时间戳,因为我可以很容易地转换&订单记录与它,也因为我从来没有尝试过DATETIME的事情。但是无论如何,如果有人告诉我我错了,我准备好改变主意。



谢谢

解决方案

Timestamp (PHP和MySQL的一个)使用32位(即4字节)存储整数;这意味着它们限于从1970年到2038年的日期范围。



DATETIME 没有限制 - 但是使用更多的字节存储(8个字节,如果我没有错误)





之后在PHP看到的存储时间戳之间,或MySQL看到的时间戳记:







另外,MySQL的 TIMESTAMP DATETIME 数据类型,请参阅 10.3.1。 DATETIME,DATE和TIMESTAMP类型


Probably many coders want to ask this question. it is What's the adventages of each one of those MySQL time formats. and which one you will prefer to use it in your apps.

For me i use Unix timestamp because maybe i find it easy to convert & order records with it, and also because i never tried the DATETIME thing. but anyways i'm ready to change my mind if anyone tells me i'm wrong.

Thanks

解决方案

Timestamp (both PHP ones and MySQL's ones) are stored using 32 bits (i.e. 4 bytes) integers ; which means they are limited to a date range that goes from 1970 to 2038.

DATETIME don't have that limitation -- but are stored using more bytes (8 bytes, if I'm not mistaken)


After, between storing timestamps as seen by PHP, or timestamps as seen by MySQL :


And, for more informations between MySQL's TIMESTAMP and DATETIME datatypes, see 10.3.1. The DATETIME, DATE, and TIMESTAMP Types

这篇关于MySQL:最好的使用,Unix TimeStamp或DATETIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆