OLEDB date(time) issue asp.net c#

我们两清 提交于 2019-12-11 04:32:00

问题


I have written a little excel helper which works fine. It uses this connection string:

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<FILENAME>;Extended Properties=\"Excel 12.0;HDR=Yes;\";";

Unfortunately when I deploy the code, cells, which contains a date string like this: 28/12/2008 are returned as: 12/25/2008 12:00:00 AM rather than 25/12/2008 00:00:00 after using ToString. I adjusted the time zone etc. of the machine (all machines are now UK time zones) but this hasn't changed anything. I am just curious what determines how OLEDB 'behaves'. The aim would be to get 25/12/2008 00:00:00 on both machines.

Thanks!

Christian


回答1:


I think that this might be something to do with the Culture being set to en-us. You would need to format the DateTime accordingly.

Standard Date and Time format strings




回答2:


The machines may need to have their locale settings changed, and not just the timezone settings. I believe they are separate.




回答3:


You have American datetime settings, either change this or use the numberformat to show it in the format you want, see http://www.mvps.org/dmcritchie/excel/datetime.htm



来源:https://stackoverflow.com/questions/4441100/oledb-datetime-issue-asp-net-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!