ASP.NET - 擴充

常常碰到DataRow撈出資料後,要把型別轉來轉去,像是DateTimeString
後來寫了個擴充就不用每次一直打 .ToString("yyyy/MM/dd")
但目前我也只會寫這種簡單的~ ㄎ

1
2
3
4
5
6
7
8
9
10
11
12
13
public static class StringExtension
{
public static string ToStringDateTime(this DateTime myDatetime)
{
return myDatetime.ToString("yyyy/MM/dd");
}
}

protected void Page_Load(object sender, EventArgs e)
{
string FuckString = DateTime.Now().ToString("yyyy/MM/dd");
string HelloString = DateTime.ToStringDateTime();
}

參考

Google

0%