最近專案中遇到乙個小問題,在資料庫存的時間戳為13位,我在mysql只能轉10位,而我想要的只是13位時間戳對應時間的日期:月-日。
在這裡我用到了幾個函式:
round() : 四捨五入(因為最後三位對應的是毫秒時間,向上向下取整沒有實際作用,但是使用哪個都可以)
from_unixtime() : 將時間戳格式化 eg:2018-05-19 00:00:00
date_format() : 取想要的時間
下面是取使用者生日日期(月-日)
birthday = 1526659200000;
# 13位時間戳轉10位
birthday/1000
round(birthday/1000)
# 時間戳轉 年-月-日 時:分:秒
from_unixtime(round(birthday/1000))
select from_unixtime(round(birthday/1000));
# 格式化為 月-日
date_format(from_unixtime(round(birthday/1000)),'%m-%d')
select date_format(from_unixtime(round(birthday/1000)),'%m-%d') as 生日;
select date_format(from_unixtime(round(birthday/1000)),'%m-%d') as 生日 from table_name where date_format(from_unixtime(round(birthday/1000)),'%m-%d') = date_format(now(),'%m-%d')
mark一下,免得自己以後忘了。 JS 10位 13位時間戳轉日期
注意 下面的date可以加個判斷是10位時間戳還是13位時間戳來進行編碼是否需要 1000 param為你要轉換的時間戳變數 if param.length 10 else if param.length 13 let date new date parseint res.data.rows i t...
js 10位 13位時間戳轉日期方法
js 處理伺服器返回的10位或者13位時間戳轉為日期方法很簡單 日期格式化 param number time 時間戳 param string format 格式 function dateformat time,format 是否補 0 const isaddzero o return form...
hive sql 13位毫秒時間戳轉日期
hive sql 中有時間戳轉日期的函式 from unixtime bigint unixtime string format 這裡面的unixtime,輸入單位是秒,也就乙個十位的bigint。但是我們實際中用的時間戳,一般都是13位的到毫秒時間戳,如果直接將該時間戳輸入方法中會有錯誤。如果是1...