ASP.NET应用程序显示美国日期格式 [英] ASP.NET Application is displaying american date formats

查看:656
本文介绍了ASP.NET应用程序显示美国日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的开发应用程序的一个今天开始显示美国格式的短日期,我期待英国格式化。

One of my development applications has today started displaying American formatted short dates where I am expecting British formatting.

日期正在呈现使用 date.ToShortDateString()

我已经检查了我的区域设置,键盘设置,浏览器设置和网页。配置。这些都设置为英语(英国)或未更改。我也重启了很多次。

I have already checked my Regional settings, keyboard settings, browser settings and web.config. These are all set to English (UK) or not changed. I've also rebooted a number of times.

同一个应用程序的移动版本,从同一个开发服务器运行,同一个网站(不同的Web应用程序)正常运行。

A mobile version of the same application, running from the same development server, and same website (different web application) is working correctly.

环境:


  • Windows 7 64位

  • Visual Studio 2010专业版

  • IIS 7.5

区域设置还可以在哪里更改可能会影响日期的显示?

Where else can Regional Settings be changed that might influence display of dates?

推荐答案

Windows区域设置不会影响任何网站,除非网站被编程为获取来自浏览器首选语言的区域设置并将其应用于ASP网站

The windows regional settings does not affect any website, unless the website is programmed to get the regional settings from the browser preferred languages and apply them to the ASP site

使用全球化 c> web.config中的$ c>选项

Use the globalization option in the web.config

<globalization culture="es-AR" uiCulture="es" />

OR

设置 global.aspx中的值 Application_BeginRequest 方法

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    Dim lang As String = "es"
    If HttpContext.Current.Request.Path.Contains("/en/") Then
        lang = "en"
    ElseIf HttpContext.Current.Request.Path.Contains("/pt/") Then
        lang = "pt"
    ElseIf HttpContext.Current.Request.Path.Contains("/es/") Then
        lang = "es"
    End If
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang)
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
End Sub

这篇关于ASP.NET应用程序显示美国日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆