linqingvoe

一、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 规定日期/时间的输出格式
  • 可以使用的格式有
  •  

  •  


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

     

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-11-19
  • 2021-11-19
猜你喜欢
  • 2021-08-05
  • 2021-12-22
  • 2022-12-23
  • 2022-02-01
相关资源
相似解决方案