2011-07-21 173 views

回答

1
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat; //--MM/dd/yyyy 
DateTimeFormatInfo ukDtfi = new CultureInfo("en-GB", false).DateTimeFormat; //--dd/MM/yyyy 
DateTime result = Convert.ToDateTime("07/21/2011", usDtfi); //or: ("21/07/2011", ukDtfi) 

然後你有一個DateTime對象(結果),並做你想做的,如:

string str = result.ToString("yyyy-MM-dd HH:mm:ss"); 

編碼快樂:)

1

試試這個

string DateString = "22/04/2011"; 
DateTime date = new DateTime(); 
date = DateTime.ParseExact(DateString, "dd/MM/yyyy"); 
string NewDateString = date.ToString("MM/dd/yyyy"); 
2

請嘗試:

string oldstr = "03/12/2011"; 
string strDate = DateTime.ParseExact(oldstr, "dd/MM/yyyy",null).ToString("MM/dd/yyyy"); 
Console.WriteLine(strDate);