DateTime的C#解析 [英] DateTime c# parsing

查看:571
本文介绍了DateTime的C#解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解析DateTime.TryParse(30-05-2010),因为它接受MMDDYYYY它抛出一个异常,而我需要DDMMYYYY格式。我怎么可以改变的TryParse格式?

I try to parse DateTime.TryParse("30-05-2010"), and it throws an exception because it accepts MMddyyyy, and I need ddMMyyyy format. how can I change TryParse format?

感谢,

达尼

推荐答案

如果你正在做,因为当地使用的调整,试试这个:

If you're making that adjustment because of local usage, try this:

bool success = DateTime.TryParse("30-05-2010", out dt);

Console.Write(success); // false

// use French rules...
success = DateTime.TryParse("30-05-2010", new CultureInfo("fr-FR"),
              System.Globalization.DateTimeStyles.AssumeLocal, out dt);

Console.Write(success); // true

这篇关于DateTime的C#解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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