Hai*_*vgi 52
类型是整数,如:
int(11)
Run Code Online (Sandbox Code Playgroud)
适用于索引和条件 > < =
OMG*_*ies 14
您想使用TIMESTAMP数据类型.
它存储为epoch值,但MySQL将值显示为"YYYY-MM-DD HH:MM:SS".
MySql DateTime数据类型以“YYYY-MM-DD HH:MM:SS”格式存储日期,范围从“1000-01-01 00:00:00”到“9999-12-31 23:59:59”。
MySql TIMESTAMP数据类型以“YYYY-MM-DD HH:MM:SS”格式存储日期,范围从“1970-01-01 00:00:01”UTC 到“2038-01-19 03:14:07”世界标准时间。
Unix TIMESTAMP是自 以来的秒数1970-01-01,如果您想将 unix 时间戳存储在mysql数据库中,您应该使用int(11)with 属性UNSIGNED(仅允许正数),如果您想保存微秒数,您应该使用bigint(20),..
如果您想unixtimestamp在选择查询中获得可读格式,您可以使用
SELECT FROM_UNIXTIME(CAST(yourtable.start_time as UNSIGNED)) as date_time
如果您正在使用,php则可以使用:
$unixtimestamp= time();//1544619186
echo(date("Y-m-d", $unixtimestamp));//2018-12-12
Run Code Online (Sandbox Code Playgroud)
如果你想在Javascript中使用本地时区显示日期时间,请使用此函数
function timeConverter(UNIX_timestamp){
var date = new Date(UNIX_timestamp*1000);
var year = date.getFullYear();
var month = ("0"+(date.getMonth()+1)).substr(-2);
var day = ("0"+date.getDate()).substr(-2);
var hour = ("0"+date.getHours()).substr(-2);
var minutes = ("0"+date.getMinutes()).substr(-2);
var seconds = ("0"+date.getSeconds()).substr(-2);
return year+"-"+month+"-"+day+" "+hour+":"+minutes+":"+seconds;
}
console.log(timeConverter(value));// 2018-14-12 13:11:33
Run Code Online (Sandbox Code Playgroud)
(在这种情况下,服务器应按原样返回 unixTimestamp
SELECT yourtable.start_time as date_time:)