如何修改系统格式日期 [英] How to chage the system format date

查看:148
本文介绍了如何修改系统格式日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个需要将日期格式从dd/mm/yyyy更改为mm/dd/yyyy的要求,反之亦然.

我有日期为12/13/2006或13/12/2007的问题.这意味着存在转换12和13的问题.有人可以帮助我解决此问题吗?

dataGridView1.Rows [rowindex] .Cells [index] .Value = Convert.ToDateTime(Column [i]).ToString(StaticVar.DateFormat);

我尝试过的事情:

我尝试过多次更改格式,但是没有
t起作用.

Hi,

I have a requirement where i need to changes the date format from dd/mm/yyyy to mm/dd/yyyy and vice versa.

I have a problem with dates having 12/13/2006 or 13/12/2007. That means there is a problem of converting 12 and 13. Can anyone please help me on this how to resolve?

dataGridView1.Rows[rowindex].Cells[index].Value = Convert.ToDateTime(Column[i]).ToString(StaticVar.DateFormat);

What I have tried:

I tried changing the format in multiple times but didn
t worked.

推荐答案

DateTime dt = DateTime.ParseExact("13/12/2006", "dd/MM/yyyy", CultureInfo.InvariantCulture);
string dtNew = dt.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);


对于问题"12/13"或"13/12",您必须知道您现在所处的文化区域.这样您就可以以正确的方式进行转换.如果您想捕获异常,那也是不可能的,因为这两个日期都可以:1/2或2/1-> 1月2日或2月1日


For the problem "12/13" or "13/12", you must know, in what cultureinfo you are right now. So that you can convert it in the right way. If you want to catch exception, that is also not possible, because these 2 dates are OK : 1/2 or 2/1 -> Jan 2nd or Feb 1st


这篇关于如何修改系统格式日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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