大家好,又见面了,我是你们的朋友全栈君。
CREATE TABLE `timestamp_string_change` (
`id` int NOT NULL AUTO_INCREMENT,
`up_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
select STR_TO_DATE(tsc.up_time, '%Y-%m-%d %H:%i:%s' ) as up_time from timestamp_string_change tsc
select from_unixtime(unix_timestamp(up_time), '%Y-%m-%d %H:%i:%s' ) as up_time from timestamp_string_change
注:方法2时,需要先用unix_timestamp()方法将数据转换成时间戳格式,再用from_unixtime()方法将时间戳转换成自定义格式时间字符串。直接用from_unixtime()方法转换出来的数据NULL。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151936.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有