2016-03-31 48 views
-2

我的日期格式就像是dd/mm/yyyy。當我試圖將其轉換爲datetime我得到這個錯誤:使用c轉換爲excel的DateTime#

System.FormatException: Le DateTime représenté par la chaîne n'est pas pris en charge dans le calendrier System.Globalization.GregorianCalendar.

英文錯誤:

System.FormatException: The datetime represented by the string is not supported in the System.Globalization.GregorianCalendar calendar.

和誤差來源是:

devises2.date_observation = DateTime.ParseExact(elements[0], 
              "dd/MM/yyyy",CultureInfo.InvariantCulture); 

你能幫助我嗎?

+1

什麼是'元素的含量[0]'導致錯誤? – ryanyuyu

+0

string []元素; – mypeeka

+1

我的意思是'元素[0]'的值是多少?什麼是導致錯誤的特定字符串? – ryanyuyu

回答

0

在你的標題中你提到了Excel。如果是如該日期值從何而來,嘗試

devises2.date_observation = DateTime.FromOADate(elements[0]); 

MSDN