开发者

What is best practise of using DateTime in different cultures

I have asp.net site. On many pages is used datetime to be putted from user and then inserted or updated some db's table with it. My problem is that I have two version of site: local for testing (Ukraine) and production (USA). Because thes开发者_如何学Ce sites have different culture datetime format are different. What is the best way to unificate workflows with datetime format? For example, I have page with textbox to be entered datetime in it and reqular expression validator. How can I do correct working with datetime in my local site ( dt format is dd.mm.yyyy) and production (mm/dd/yyyy) ? Thanks.


Just make sure you use the correct CultureInfo for parsing and formatting. Where you get the cultureinfo from is the tricky question, you could for example deduce it from the users browser language. On the server side, always store culture-neutral values, i.e. never store dates & times as strings in a database for example.

DateTime validation should always be culture aware. For server side validation, use e.g. "TryParse()" to validate. For client side validation you need to be equally careful with cultures. There probably exists numerous javascript libraries that will validate dates in different cultures.


You can define culuture in web.config and code correspondingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜