從數據庫讀取時間出現上下午的問題
我們把問題簡單點,在數據庫中建個表只有一個字段,datetime屬性。 
 我往數據庫中放入插入一條記錄, 
 SqlCommand   cmd=new   SqlCommand( "insert   into   timetest   values(getdate) ",con); 
 插入後,用查詢分析器,查看時間正常   
 再讀出來 
 SqlCommand   cmd=new   SqlCommand( "select   top   1   *   from   timetest,con); 
 con.Open(); 
 string   time=(Convert.ToDateTime(cmd.ExecuteScalar())).ToString(); 
 con.Close();   
 用label把time顯示出來是   2007/5/15   上午   11:46:52(注意,有個 "上午 ") 
 而在數據庫中是2007-05-05   11:46:52.753   
 我現在想不要那個上下午。直接用24小時制來顯示,請問怎麼搞。 
 因為出現上下午後,好像就不好轉化到datetime
------解决方案--------------------up
------解决方案--------------------直接严格控制显示格式
------解决方案--------------------datetime.ToString( "yyyy-MM-dd hh:mm:ss ");   
 另参考 
 http://www.cnblogs.com/coolstr/archive/2007/04/04/700522.html
------解决方案--------------------啊 
 过兄两星了.. 
 散分没有??
------解决方案--------------------不不转成DateTime 试试 
 如果不行就按楼上的
------解决方案--------------------用datetime.tostring(),以下为转换格式   
 1.14 取当前时间,格式为:2003-09-23T14:46:48  
 string strT=currentTime.ToString( "s ");    
 1.15 取当前时间,格式为:2003-09-23 14:48:30Z  
 string strT=currentTime.ToString( "u ");    
 1.16 取当前时间,格式为:2003-09-23 14:48  
 string strT=currentTime.ToString( "g ");    
 1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT  
 string strT=currentTime.ToString( "r ");    
 1.18获得当前时间 n 天后的日期时间  
 DateTime newDay = DateTime.Now.AddDays(100);  
------解决方案--------------------datetime.ToString( "yyyy-MM-dd hh:mm:ss ");
------解决方案--------------------string time=(Convert.ToDateTime(cmd.ExecuteScalar())).ToString( "yyyy-MM-dd HH:mm:ss "); 
------解决方案--------------------1.datetime.ToString( "yyyy-MM-dd hh:mm:ss "); 
 2.先转换成string 类型再用Substing截取
------解决方案--------------------时间格式而已,可能是你的服务器时间设置成了带 "上午 "的也有可能是你数据库设置的.其实不管是哪里设置的,你把它转化成你要的格式就可以了