數據格式化

1 取值後格式化
{0:d}小型:如2005-5-6
{0:D}大型:如2005年5月6日
{0:f}完整型

2 當前時間獲取
DateTime.Now.ToShortDateString

3 取值中格式化
SQL Server裏面可能經常會用到的日期格式轉換方法:

舉例如下:

select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08

select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')
20040912110608

select CONVERT(varchar(12) , getdate(), 111 )
2004/09/12

select CONVERT(varchar(12) , getdate(), 112 )
20040912

select CONVERT(varchar(12) , getdate(), 102 )
2004.09.12

其它我不常用的日期格式轉換方法:

select CONVERT(varchar(12) , getdate(), 101 )
09/12/2004

select CONVERT(varchar(12) , getdate(), 103 )
12/09/2004

select CONVERT(varchar(12) , getdate(), 104 )
12.09.2004

select CONVERT(varchar(12) , getdate(), 105 )
12-09-2004

select CONVERT(varchar(12) , getdate(), 106 )
12 09 2004

select CONVERT(varchar(12) , getdate(), 107 )
09 12, 2004

select CONVERT(varchar(12) , getdate(), 108 )
11:06:08

select CONVERT(varchar(12) , getdate(), 109 )
09 12 2004 1

select CONVERT(varchar(12) , getdate(), 110 )
09-12-2004

select CONVERT(varchar(12) , getdate(), 113 )
12 09 2004 1

select CONVERT(varchar(12) , getdate(), 114 )
11:06:08.177

//string處理
string.ToString("0.00")
String.Format("{0:N2}",string)

//綁定處理
<asp:BoundColumn DataField="TotalPrice" HeaderText="小計(元)" DataFormatString="{0:c}"></asp:BoundColumn>

<ItemTemplate><# DataBinder.Eval(Container.DataItem, "Order_TotalPri","{0:c}") %></ItemTemplate>

//對價格進行四捨五入
string myPrice = String.Format("{0:N2}", Math.Round((Convert.ToDouble(price)*Convert.ToDouble(discount)*0.1),2));

DATAGRID
{0:0.0}

 


本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/Eray/archive/2007/04/23/1575273.aspx

發佈了28 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章