日期操纵日期算术 [英] date manipulation date arithmetic
本文介绍了日期操纵日期算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要编程并获得以下日期
1. 2014年9月1日
2 2014年1月1日
请协助代码。
Need to program and get the following dates
1. 1 Sep 2014
2 1 Jan 2014
please assist with codes.
推荐答案
看看 DateTime构造函数。
这将向您展示如何在C#中创建DateTime对象。
您可以像这样使用它:
Hi,
Have a look at the DateTime Constructor.
This will show you how to create DateTime objects in C#.
You can use it like this:
DateTime dtFirstDate = new DateTime(2014, 9, 1);
DateTime dtSecondDate = new DateTime(2014, 1, 1);
希望它有所帮助。
Hope it helps.
尝试:
Try:
DateTime dt1;
if (!DateTime.TryParse("1 Sep 2014", out dt1))
{
// Report error to whatever
return;
}
DateTime dt2;
if (!DateTime.TryParse("1 Jan 2014", out dt2))
{
// Report error to whatever
return;
}
TimeSpan diff = dt1 - dt2;
这篇关于日期操纵日期算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文