2015-08-19T14:58:10.000-03:00 格式的字符串插入时间类型字段

MySql 码拜 9年前 (2015-10-19) 1013次浏览
2015-08-19T14:58:10.000-03:00   格式的字符串插入时间类型字段,需要怎么去格式化
解决方案:10分
引用

STR_TO_DATE(str,format) 
This is the inverse of the DATE_FORMAT() function. It takes a string str and a format string format. STR_TO_DATE() returns a DATETIME value if the format string contains both date and time parts, or a DATE or TIME value if the string contains only date or time parts. If the date, time, or datetime value extracted from str is illegal, STR_TO_DATE() returns NULL and produces a warning. 
The server scans str attempting to match format to it. The format string can contain literal characters and format specifiers beginning with %. Literal characters in format must match literally in str. Format specifiers in format must match a date or time part in str. For the specifiers that can be used in format, see the DATE_FORMAT() function description. 
mysql> SELECT STR_TO_DATE(“”01,5,2013″”,””%d,%m,%Y””);

        -> “”2013-05-01″”

mysql> SELECT STR_TO_DATE(“”May 1, 2013″”,””%M %d,%Y””);

        -> “”2013-05-01″”
Scanning starts at the beginning of str and fails if format is found not to match. Extra characters at the end of str are ignored. 
mysql> SELECT STR_TO_DATE(“”a09:30:17″”,””a%h:%i:%s””);

        -> “”09:30:17″”

mysql> SELECT STR_TO_DATE(“”a09:30:17″”,””%h:%i:%s””);

        -> NULL

mysql> SELECT STR_TO_DATE(“”09:30:17a””,””%h:%i:%s””);

        -> “”09:30:17″”
Unspecified date or time parts have a value of 0, so incompletely specified values in str produce a result with some or all parts set to 0: 
mysql> SELECT STR_TO_DATE(“”abc””,””abc””);

        -> “”0000-00-00″”

mysql> SELECT STR_TO_DATE(“”9″”,””%m””);

        -> “”0000-09-00″”

mysql> SELECT STR_TO_DATE(“”9″”,””%s””);

        -> “”00:00:09″”

.

解决方案:20分

确实有这个问题,本人在mysql官方文档里查了,也没查到 这个函数中有时区的 格式

解决方案:10分

“”2015-08-19T14:58:10.000-03:00″”   这个格式, 

在C#里面,將日期时间用tostring(“o”)格式化出来的, 其他语言,就不知道是啥函数格式化来的了。
你官方也沒查到时区怎么变回去,估计还是得从程序入手传datetime 格式数据来了。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明2015-08-19T14:58:10.000-03:00 格式的字符串插入时间类型字段
喜欢 (0)
[1034331897@qq.com]
分享 (0)