方法1.HTML:
<asp:BoundColumn DataField="date_sche_ship" HeaderText="dateScheduleShip" DataFormatString="{0:dd-MM-yyyy}"></asp:BoundColumn>
方法2.CS:
public static string dateFormat(string date)
{
string tempDate = "";
string tempStr1 = "";
string tempStr2 = "";
string tempStr3 = "";
int firstIndex, lastIndex,length;
if(date != "")
{
tempDate = date.Trim();
firstIndex = tempDate.IndexOf('/');
lastIndex = tempDate.LastIndexOf('/');
if(firstIndex != -1 && lastIndex != -1)
{
length = tempDate.Length;
tempStr1 = tempDate;
tempStr1 = tempStr1.Substring(0,firstIndex);
tempStr2 = tempDate;
tempStr2 = tempStr2.Substring(firstIndex + 1,lastIndex - firstIndex - 1);
tempStr3 = tempDate;
tempStr3 = tempStr3.Substring(lastIndex + 1,length - lastIndex - 1);
tempDate = tempStr3 + "-" + tempStr1 + "-" + tempStr2;
}
else
tempDate = date;
}
else
tempDate = date;
return tempDate;
}
{
string tempDate = "";
string tempStr1 = "";
string tempStr2 = "";
string tempStr3 = "";
int firstIndex, lastIndex,length;
if(date != "")
{
tempDate = date.Trim();
firstIndex = tempDate.IndexOf('/');
lastIndex = tempDate.LastIndexOf('/');
if(firstIndex != -1 && lastIndex != -1)
{
length = tempDate.Length;
tempStr1 = tempDate;
tempStr1 = tempStr1.Substring(0,firstIndex);
tempStr2 = tempDate;
tempStr2 = tempStr2.Substring(firstIndex + 1,lastIndex - firstIndex - 1);
tempStr3 = tempDate;
tempStr3 = tempStr3.Substring(lastIndex + 1,length - lastIndex - 1);
tempDate = tempStr3 + "-" + tempStr1 + "-" + tempStr2;
}
else
tempDate = date;
}
else
tempDate = date;
return tempDate;
}