将DateTime转换为MySQL TimeStamp [英] Convert DateTime to MySQL TimeStamp
本文介绍了将DateTime转换为MySQL TimeStamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这样做是为了在MySQL数据库中保存 DateTime
,但是在存储时,值是 2011-10-30 06:01: 07
。 06
应该是 pm
,而不是 am
:
I am doing this to save a DateTime
in the MySQL database but when stored, the value is 2011-10-30 06:01:07
. 06
is supposed to be pm
, not am
:
startTime.ToString("yyyy-MM-dd hh:mm:ss");
推荐答案
只需这样做
startTime.ToString ("yyyy-MM-dd HH:mm:ss");
其中 HH
(大写H)显示24小时格式。因此,当您尝试保存 2011-10-30 06:01:07
时,假设是 am
,并且在需要时 pm
您应该保存 2011-10-30 18:01:07
where HH
(capital H) shows 24 hours format. So when you try saving 2011-10-30 06:01:07
it suppose to be am
and when you want pm
you should save 2011-10-30 18:01:07
这篇关于将DateTime转换为MySQL TimeStamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文