一、MySQL 日期和时间戳的转换

1.日期转时间戳

select UNIX_TIMESTAMP('2018-12-25 12:25:00');
结果:1545711900



2.时间戳转日期:FROM_UNIXTIME(unix_timestamp) --unix_timestamp为时间戳

select FROM_UNIXTIME(1545711900);
结果:2018-12-25 12:25:00



3.时间戳转日期,自定义返回日期格式:FROM_UNIXTIME(unix_timestamp,format) -- format请参考后面的截图

select FROM_UNIXTIME(1545711900,'%Y-%m-%d %T');
-- 结果:2018-12-25 12:25:00

  

二、DATE_FORMAT(date,format)函数用于以不同的格式显示日期/时间数据

  • date 参数是合法的日期。format 规定日期/时间的输出格式
  • 可以使用的格式有

MySql格式转换

MySql格式转换

示例:

select DATE_FORMAT(NOW(), '%Y-%m-%d %T');

结果:2018-12-25 12:25:00

示例:


select DATE_FORMAT(NOW(), '%Y-%m-%d %T');
结果:2018-12-25 12:25:00

相关文章:

  • 2021-09-02
  • 2021-10-01
  • 2021-10-09
  • 2021-06-03
  • 2021-07-03
  • 2022-01-30
  • 2021-06-14
  • 2021-06-01
猜你喜欢
  • 2021-12-26
  • 2022-12-23
  • 2021-08-14
  • 2021-12-04
  • 2021-12-05
  • 2021-07-25
  • 2022-01-09
相关资源
相似解决方案