ksaa0096329
V2EX  ›  问与答

问一个 mysql 字段类型的问题

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