.Net中的DateTime问题 [英] DateTime issue in .Net

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

问题描述

Hello All,



我想在类的初始值设定项中将日期设置为01/01/1900。

为此,我使用以下代码:

Hello All,

I am trying to set a date as "01/01/1900" in the initializer of a class.
For this I am using following code:

private DateTime Delivery_Date = DateTime.ParseExact("01/01/1900", "MM/dd/yyyy", null);



抛出错误。

我的系统日期格式为dd-MM-yyyy。

当我将系统日期格式从dd-MM-yyyy更改为dd / MM时/ YYYY。上面的代码工作正常。



请帮忙。



谢谢,

Nitin


This throws error.
My Systems date format is dd-MM-yyyy.
When I change the System date format from dd-MM-yyyy to dd/MM/yyyy. The above code works fine.

Please help.

Thanks,
Nitin

推荐答案

为什么不使用:

Why not use:
private DateTime Delivery_Date = new DateTime(1900, 1, 1);


您好,

请试试这个



Hello,
Please try this

DateTime myDt = DateTime.ParseExact("1900-01-01", "yyyy-MM-dd",
                                       System.Globalization.CultureInfo.InvariantCulture)


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

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