日期时间范围 [英] DateTime range

查看:83
本文介绍了日期时间范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想用c#来获取日期范围。

我可以通过date1 = DateTime.Now()获得一个范围。


但是如果我想回去说5天我怎么去计算日期




我正在寻找一个DateTime函数,它将日期转换为

整数,然后将其转换回来,但没有运气。


任何建议都会赞赏


提前致谢


比尔

Hi

I am trying to get a date range in c#.
I can get the one range by date1 = DateTime.Now();

But if I wanted to go back say 5 days how do I go about calculating the date
for that.

I was looking for a DateTime function that would convert the date into an
integer and then convert it back but without luck.

Any suggestions would be appreciated

Thanks in advance

Bill

推荐答案

使用AddDays方法。


DateTime date1 = DateTime.Now;

DateTime date2 = date1.AddDays(-5);


-

Tim Wilson

..Net Compact Framework MVP


"比尔" < FH *********** @ rogers.com>在消息中写道

新闻:我们******************** @ rogers.com ...
Use the AddDays method.

DateTime date1 = DateTime.Now;
DateTime date2 = date1.AddDays(-5);

--
Tim Wilson
..Net Compact Framework MVP

"Bill" <fh***********@rogers.com> wrote in message
news:We********************@rogers.com...
你好

我想用c#来获取日期范围。
我可以通过date1 = DateTime.Now()得到一个范围;

但是如果我想要的话回去说5天我如何计算
日期。

我正在寻找一个DateTime函数,将日期转换为
整数然后将其转换回来,但没有运气。

任何建议都将不胜感激

提前致谢

比尔
Hi

I am trying to get a date range in c#.
I can get the one range by date1 = DateTime.Now();

But if I wanted to go back say 5 days how do I go about calculating the date for that.

I was looking for a DateTime function that would convert the date into an
integer and then convert it back but without luck.

Any suggestions would be appreciated

Thanks in advance

Bill



date1.Subtract(new TimeSpan(5,0,0,0));


Dale Preston

MCAD,MCDBA,MCSE

" Bill" < FH *********** @ rogers.com>在消息中写道

新闻:我们******************** @ rogers.com ...
date1.Subtract(new TimeSpan(5,0,0,0));

Dale Preston
MCAD, MCDBA, MCSE

"Bill" <fh***********@rogers.com> wrote in message
news:We********************@rogers.com...
你好

我想用c#来获取日期范围。
我可以通过date1 = DateTime.Now()得到一个范围;

但是如果我想要的话回去说5天我如何计算
日期。

我正在寻找一个DateTime函数,将日期转换为
整数然后将其转换回来,但没有运气。

任何建议都将不胜感激

提前致谢

比尔
Hi

I am trying to get a date range in c#.
I can get the one range by date1 = DateTime.Now();

But if I wanted to go back say 5 days how do I go about calculating the date for that.

I was looking for a DateTime function that would convert the date into an
integer and then convert it back but without luck.

Any suggestions would be appreciated

Thanks in advance

Bill



你试过吗,


DateTime fiveDaysAgo = DateTime.Now()。AddDays(-5);




Have you tried,

DateTime fiveDaysAgo = DateTime.Now().AddDays(-5);

?


这篇关于日期时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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