简体   繁体   中英

Date Conversion Problem

i have Converted by code Date Formate DD/MM/YYYY Locally but when Publish Application on Windows Server 2008 then Automatically display date in MM/DD/yyyy any body tell me what is Problem.. so Windows server 2008 display date in DD/MM/YYYY Code is as Under which is not working

    System.IFormatProvider frmt = default(System.IFormatProvider);
    frmt = new System.Globalization.CultureInfo("en-US", true);
    dtDate1 = Convert.ToDateTime(txtFromDate.Text,  frmt);

Date conversion (from string) using DateTime.Parse() has the nasty habbit of using the locale settings for the computer it is running.

A better way of converting is to run DateTime.TryParseExact() and explicitly supply your expected date formats.

Your regional setting on server are probably different from your workstation; you could use DateTime.ParseExact to make your application culture safe

如果希望日期格式与区域设置无关,请确保服务器上的区域设置正确,和/或在应用程序中使用显式格式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM