开发环境和服务器中的差异日期格式 [英] Difference date format in development environment and server

查看:76
本文介绍了开发环境和服务器中的差异日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我将在一个report.im中使用Visual Studio 2010和sql Server 2008在问题的帮助下解释我的问题.在我的开发系统中,我会从数据库中检索详细信息,并且其日期可以正常工作.在文本框中,我会在dd中显示日期/mm/yy格式

Hi all

I will explain my issue with the help of problem in one report.im using visual studio 2010 and sql server 2008 .In my development system i retrieve the details from database with in a date its working well .In text box im displaying date in dd/mm/yy format

ld_fromdate = Convert.ToDateTime(como.ff_SetDate(txtcreatedfromdate.Text));
public string ff_SetDate(string datetime)
    {
            string[] date = datetime.Split('/');
            string DD = date[0];
            string MM = date[1];
            string YY = date[2];
            string dt = DD +"/"+ MM +"/"+ YY;
            return (dt);
       
    }


当我将其添加到服务器时,它不起作用,而是下面的转换代码起作用了


when i add this to server its not working instead the below code of conversion is working

public string ff_mm_dd_yy_Date(string strDate)
       {
               string DD, Mm, Yy;
               string[] str = strDate.Split('/');
               DD = str[0];
               Mm = str[1];
               Yy = str[2];
               return ("" + Mm +"/"+ DD +"/"+ Yy + "";);
       }


第一个在开发环境中工作的计算机,第二个在服务器中工作.由于服务器中托管的许多其他应用程序,我无法更改系统设置.如何通过编码进行维护
在此先感谢
Amritha


first one working in development environment secon one working in server.as many other applications hosted in server i cant change system settings .how can i maintain through coding
Thanks in Advance
Amritha

推荐答案

您的问题可能是服务器设置为与开发计算机不同的语言环境.

如果您的开发机设置为欧洲日期DD/MM/YY,而服务器设置为美国日期MM/DD/YY,则将获得此效果,因为Convert.ToDateTime方法使用当前语言环境来决定如何评估日期.

使用 DateTime.TryParseExact [
Your problem is probably that the server is set to a different locale to your development machine.

If you dev machine is set to European dates DD/MM/YY and your server is set to US dates MM/DD/YY then you will get this effect because the Convert.ToDateTime method uses the current locale to decide how to evaluate the date.

Use the DateTime.TryParseExact[^] method instead - you can specify the date format exactly that way.


这篇关于开发环境和服务器中的差异日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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