问题
We have a WCF web service returns back some xml containing a datetime value as a string. The value is first read out from a database and then appended to an xml string using .ToString().
We have a number of web servers running but this particular one is converting the datetime value to a 24 hour value, we need it has a 12 hour value but I can't figure out how to change IIS default date format. I have tried changing the regional settings and have look at the culture and ui culture values of the web service which are both set to "Invariant Language (Invariant Country)".
I think it might require a registry change. Does anyone know how to change the datetime format of a web service?
We cannot change the code at this stage so my only choice is to update the server itself.
Its running on windows server 2008.
thank you
回答1:
Nevermind people I've figured it out. To change the datetime regional settings of an IIS website/webs ervice here is what you do:
First go into IIS and click on the website/web service you want to configure. On the right hand side open up .Net Globalization and change the culture and ui culture to anything other than the one you want.
Now in the control panel go into the region and language screen and change the datetime format to what you want it to be. Then on the administration tab of the region and language screen click the "Copy settings" button and tick the box "Welcome screen and system accounts". Click ok on both screens to exit region and language.
Now go back to IIS and change the culture and ui culture back to what it was before you change it. Your website/webservice should now be serving up the correct datetime format.
I think the key point here is copying the region and language settings to all system users. then changing the IIS culture settings makes IIS pickup the new settings. You might get away with not changing the culture and simply restarting the webserver or the machine after making the changes in the region and language screen but i haven't tried this.
来源:https://stackoverflow.com/questions/16556563/iis-default-datetime-format