2009-02-07 45 views
0

我通過設置我的.NET應用程序的語言環境:ASP.NET,SQL服務器,LINQTOSQL和日期格式

string userLocale = Web.Helpers.LocaleHelpers.GetBestRFC3066Locale(this.Context.Request.UserLanguages); 

      if (userLocale != String.Empty) 
      { 
       System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(userLocale); 
       System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(userLocale); 
      } 

這個效果很好,所以我的日期將根據區域設置顯示格式即

12/10/2009爲EN-GB 和 10/12/2009爲我們

然而,當我通過LinqToSql堅持我的日期,我需要這些日期存儲在一個共同的格式。

當前美國用戶正在運行該應用程序時,存儲在數據庫中的日期爲美國格式,並且當英國用戶使用該應用程序時,其格式爲英文。

關於如何最好地實現這一點的任何建議?

回答

2

將日期存儲爲SQL Server中的datetime值。那麼你不會遇到轉換問題。

0

Brannon在那裏有正確的解決方案。一旦在SQL中使用日期時間格式的變量,則可以使用CONVERT T-SQL關鍵字將其轉換爲其他日期時間格式