MySQL时间戳(毫秒/秒)与日期格式的相互转换

  1. 查看数据库时区
show variables like'%time_zone';
  1. 时间戳转日期格式,使用MYSQL自带的函数FROM_UNIXTIME(unix_timestamp,format)。
select FROM_UNIXTIME(1650167899000/1000,'%Y-%m-%d %h:%i:%s') as date

输出:

2022-04-17 03:58:19
  1. 日期格式转时间戳
select UNIX_TIMESTAMP('2022-04-17 03:58:19')  as date

输出:

1650167899

你可能感兴趣的:(mysql,mysql)