ASP日期格式使用客户文化code-背后 [英] ASP date format using client culture code-behind
问题描述
我有一个的SQLServer
DB ASP.NET Web应用程序和数据。
I have an ASP.NET web application and data in a SQLServer
DB.
什么是显示在客户端的文化格式的日期(使用LINQ中提取)的最佳方式,从code-落后。
What is the best way to display a date (extracted with LINQ) in the client's culture format, from code-behind.
我的意思是我有来自美国和欧洲的用户,他们希望不同的格式: MM / DD / YYYY
(美国)或 DD / MM / YYYY(英国)
?
I mean I have users from USA and from Europe, they want different formats: MM/dd/yyyy
(US) or dd/MM/yyyy (UK)
?
我想是这样的:
from myData in dbContext.myFile
Where .../...
Select myFile.birthDate.ToString.(**some magic formating here**)
更新:由于达林快速的答案
Update: Thanks to Darin for quick answer!
提示:如果使用IE,不要忘记检查什么是$ P $使用pferred郎咸平:
看在工具/ Internet选项/语言
Tip: if using IE, don't forget to check what is the preferred lang in use: Look in Tools / Internet options / Languages
推荐答案
您可以在文化设置为自动在的 <全球化与GT;
你的web.config的元素:
You could set the culture to auto in the <globalization>
element of your web.config:
<globalization culture="auto" uiCulture="auto" />
将使用客户端浏览器的培养。然后,只需使用的ToString()
:
<%= DateTime.Now.ToString() %>
或 ToShortDateString
取决于你想要的格式。
or ToShortDateString
depending on the format you want.
这篇关于ASP日期格式使用客户文化code-背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!