ksaa0096329
V2EX  ›  问与答

问一个 mysql 字段类型的问题

  •  
  •   ksaa0096329 · Sep 28, 2018 · 2562 views
    This topic created in 2959 days ago, the information mentioned may be changed or developed.
    定义表结构时,时间我选择的是 timestamp,插入数据都没有问题.
    但是 select 出来的数据为什么就是 datetime 格式的,是不是和 mysql 版本有关?
    我想要获取数字字符串格式的,难道还要使用 mysql 的函数?
    求解答

    5 replies  •  2018-09-29 09:51:21 +08:00
    815979670
    815979670
    Sep 28, 2018 via Android❤️1
    1
    时间戳格式就存 int 类型 MySQL 的时间类型都会自动转为时间格式,
    newtype0092
    newtype0092
    Sep 28, 2018
    2
    默认 timestamp 就显示成系统设置的时间格式,需要时间戳用 unix_timestamp(time) 转一下。
    newtype0092
    newtype0092
    Sep 28, 2018❤️1
    3
    一般都是存成 int,需要时间字符串的话用
    date_format(, '%Y-%m-%d %H:%i:%s')
    newtype0092
    newtype0092
    Sep 28, 2018
    4
    @newtype0092
    手滑。。。
    用 from_unixtime(int_timestamp) 转成默认日期格式
    或者 date_format(from_unixtime(int_timestamp), '%Y-%m-%d %H:%i:%s') 自定义格式
    ksaa0096329
    ksaa0096329
    OP
    Sep 29, 2018
    5
    @newtype0092 了解了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5481 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:02 · PVG 10:02 · LAX 18:02 · JFK 21:02
    ♥ Do have faith in what you're doing.