mysql中的時間戳和日期時間的轉換

2021-08-05 21:41:17 字數 620 閱讀 4582

1、unix時間戳轉換為日期用函式: from_unixtime()

select from_unixtime(1156219870); 

輸出:2006-08-22 12:11:10

2、日期轉換為unix時間戳用函式: unix_timestamp()

select unix_timestamp('2006-11-04 12:23:00'); 

輸出:1162614180 

select unix_timestamp(now()); 

輸出當前時間戳 

例:mysql查詢當天的記錄數:

$sql=」select * from message where date_format(from_unixtime(chattime),』%y-%m-%d』) = date_format(now(),』%y-%m-%d』) order by id desc」; 

php方式轉換:

unix時間戳轉換為日期用函式: date()

date('y-m-d h:i:s', 1156219870);

日期轉換為unix時間戳用函式:strtotime()

strtotime('2010-03-24 08:15:42');

mysql時間戳和日期轉換

mysql有自帶的函式可以直接轉換,函式是from unixtime 資料表中 create time 儲存的是時間戳,如 1429063399 mysql的執行語句 日期合格可以自己定義 select from unixtime 1429063399,y m d h i s 輸出結果 mysql的...

MySQL時間戳轉日期

使用from unixtime函式,具體如下 from unixtime unix timestamp,format 返回表示 unix 時間標記的乙個字串,根據format字串格式化。format可以包含與date format 函式列出的條目同樣的修飾符。下列修飾符可以被用在format字串中 ...

Android 獲取時間戳 和時間戳轉日期

獲取系統時間戳 public string gettime 獲取系統時間 long currenttime system.currenttimemillis dateformat formatter new dateformat yyyy年 mm月dd日 hh時mm分ss秒 date date ne...