Culture in a Silverlight application
I'm developing a Silverlight application which is translated to multiple languages. It's a business application, and people from many different countries use it.
The strings in the user interface of the application will be dependant on what UICulture is being used, which is set depending on what language the web browser is configured to use. If the users browser is configured to use an language which we have not translated to, we simply override the UICulture to display the en-US translation. For instance, if the user is using the en-GB language we choose to display the en-US translation instead.
Now I'm trying to understand if something similar is needed for the Culture of the application (note: not UICulture). For instance, if a UK user uses my Silverlight app, he wants his dates to be presented in the format DD/MM/YYYY. But if a US user uses it, he wants to have it formatted according to MM/DD/YYYY. If a swedish guy comes along, he wants YYYY-MM-DD. As far as I can tell, all this is taken care of automatically (it varies depending on language selected in web browser). And as long as I use proper data types to represent the values (DateTime to represent a date for instance) and don't assume stupid things (such as assuming that DateTime.Now.ToString() will always return a date in format YYYY-MM-DD regardless of user culture I believe I don't have to do something special in regards to Culture.
I realize that web services called by the app either must take DateTime as parameter, or, if the web service always assumes dates in string format YYYYMMDD, the client code must format the date properly before calling the web servie.
My question:
Is it in some situation neccessary to override the default Culture of the Silverlight application to prevent stuff from breaking?
I also realize that some users may prefer to choose Culture themself, rather than the app relying on the web browser setting, but that's not a requirement yet. I'm more trying to understand if NOT overriding Culture can in some cases break things.
You can use this:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB");
ci.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
ci.DateTimeFormat.ShortTimePattern = "HH:mm:ss tt";
and suppose you have your date in DATE
var.
then use it as
var date= System.DateTime.Parse(VitalinfoArray[2].Trim(),ci);
It will give date according to the culture of your browser.
链接地址: http://www.djcxy.com/p/75094.html