Web Service Date Time Parameter won't accept UK format DD/MM/YYYY
I have created a Web Service and deployed it on an internal server here. The server is set to UK datetime format.
开发者_运维问答The Web Service contains one method with the following signature:
public Result Scan(string value, string data, DateTime ScanDateTime)
{
}
When testing the webservice locally on the server, it will only accept values for the 3rd parameter in American datetime format. I need to work with UK date time format but I can't find a way to change this. All accounts and system locale are set to UK format.
You can change the culture being used at runtime, however i'd strongly suggest holding a standardized format of yyyy-MM-dd
since all cultures understand this format.
Because Web Service server-side code for input uses local culture settings which are different from en-GB
, i.e. en-US
.
But output data becomes formatted using client culture settings.
Input format should be documented by server maintainers and you should follow them.
Some DateTime conversion examples:
DateTime enGb = DateTime.ParseExact("02/09/2010", "dd/MM/yyyy", new CultureInfo("en-GB"));
string enUS_full = enGb.ToString(new CultureInfo("en-US")); // 9/2/2010 12:00:00 AM
string enUS_date = enGb.ToString("MM/dd/yyyy"); // 9/2/2010
string iso = enGb.ToString("yyyy-MM-dd"); // 2010-09-02
also you can use not hard-coded format but pre-configured:
string enUS = enGb.ToString(new CultureInfo("en-US").DateTimeFormat.ShortDatePattern); // 9/2/2010
string iso = enGb.ToString(CultureInfo.InstalledUICulture.DateTimeFormat.ShortDatePattern); // 2010-09-02
精彩评论