mysql怎么把日期格式化成年月日时分秒?

如题所述

datetime包含毫秒,要格式化输出,用fff

DateTime t = DateTime.Now;

Console.WriteLine(t.ToString("yyyy-MM-dd hh:mm:ss fff"));

注:mysql里面的datetime类型的精确度是可以到1/ 10 ^ 6 秒的,某些客户端(如navicat for mysql)的显示经常只能看到精确到秒,其实是设计表的时候的配置问题。

扩展资料:

mysql中DateTime和Timestamp

DateTime

1、8个字节储存(8 bytes storage)

2、实际格式储存(Just stores what you have stored and retrieves the same thing which you have stored.)

3、与时区无关(It has nothing to deal with the TIMEZONE and Conversion.)

4、存储的时间范围为:'1000-01-01 00:00:00.000000' 到 '9999-12-31 23:59:59.999999'

Timestamp

1、4个字节储存(Time stamp value is stored in 4 bytes)

2、值以UTC格式保存( it stores the number of milliseconds)

3、时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区。

4、存储的时间范围为:'1970-01-01 00:00:01.000000' 到 '2038-01-19 03:14:07.999999'

温馨提示:答案为网友推荐,仅供参考