简体   繁体   English

MySQL默认current_timestamp不以24小时军事格式存储

[英]Mysql default current_timestamp not storing in 24 hour military format

I have a simple table like this: 我有一个简单的表,像这样:

CREATE TABLE `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `username` varchar(16) DEFAULT NULL,
  `password` varchar(16) DEFAULT NULL
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Whenever I insert a record, the created field should be automatically filled with the current timestamp. 每当我插入记录时,创建的字段都应自动填充当前时间戳。 However, for some reason I keep seeing the inserted timestamp in a 12 hour format. 但是,由于某些原因,我一直看到插入的时间戳为12小时格式。 When I do something like select created from users limit 1; 当我执行select created from users limit 1; I would get 2012-04-30 11:34:05 我会得到2012-04-30 11:34:05

When I do something like select current_timestamp I would get the 24 hour format 2012-04-30 23:34:05 当我执行select current_timestamp我将获得24小时格式2012-04-30 23:34:05

When I cast it to unix_time and ask php to convert it to PST time, it's correct. 当我将其转换为unix_time并要求php将其转换为PST时间时,这是正确的。 But I would like to have the column be displayed in 24 hour format without any time manipulation. 但我希望该列以24小时格式显示,而无需进行任何时间操作。 Can anyone help? 有人可以帮忙吗?

As Mitch said in the comment above, it seems like just a matter of formatting the output on your SELECT . 正如Mitch在上面的评论中所说,这似乎只是格式化SELECT上的输出的问题。 Try DATE_FORMAT : 试试DATE_FORMAT

SELECT DATE_FORMAT(created, '%Y-%c-%e %H:%i:%s') FROM users

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM