通过datetime func获得4个日期的frm当前日期 [英] to get 4 dates frm present date by datetime func

查看:68
本文介绍了通过datetime func获得4个日期的frm当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,

我必须从当前日期时间中获取4个日期.

IE.如果是2011年4月8日,我想获得2011年1月1日,2011年6月30日,2011年7月1日和2011年12月30日.

如果可能,通过使用c#
在asp.net中使用datetime函数
[回应答案] :

是的,我希望它们反映为两个六个月的期间,从包含日期的输入日期开始.

如果日期是2011年4月8日,那么我要2011年1月1日和2011年6月30日(上半年)

如果日期是2011年7月7日,那么我想要2011年7月1日和2011年12月30日.我猜是今年.如果是,那么可以这样做:


DateTime input = someInputValue;
DateTime out1 = new DateTime(input.Year, 1,1);
DateTime out2 = new DateTime(input.Year, 6,30);
DateTime out3 = new DateTime(input.Year, 7,1);
DateTime out4 = new DateTime(input.Year, 12,31);


从这个问题尚不清楚您实际上在追求什么.
您希望日期在输入日期4月8日前后一定天数吗?
或者,您是否希望它们固定但与年份相关?
也许您希望它们反映为两个六个月的期间,从包含日期的输入日期开始.
(即,如果输入日期为9月15日,则为1/7/11、31/12/11、1/1/12、30/6/12?

因此,请在问题上更加精确和简洁.

(还请注意,做日期"时需要考虑Le年,所以这不仅仅是增加x天数的问题.)


Please Help,

I have to obtain 4 dates from the present datetime.

IE. If it is 8th April 2011, I want to obtain 1st Jan 2011, 30th Jun 2011, 1st July 2011 and 30th Dec 2011.

If possible, by using datetime functions in asp.net using c #

[In response to Answers]:

ya i want them reflected as two six month periods starting with the inclusive input date.

if date is 8 april 2011 then i want 1 jan 2011 and 30 jun 2011 (first half year )

if date is 7 july 2011 then i want 1 jul 2011 and 30 dec 2011

解决方案

I am not sure about the realtion between input datea and four output dates. I guess it is the year. If yes, then it can be done like this:


DateTime input = someInputValue;
DateTime out1 = new DateTime(input.Year, 1,1);
DateTime out2 = new DateTime(input.Year, 6,30);
DateTime out3 = new DateTime(input.Year, 7,1);
DateTime out4 = new DateTime(input.Year, 12,31);


It is unclear from the question what you are actually after.
Do you wish the dates to be a certain number of days before and and after the input date of 8th April?
Or, do you want them to be fixed, but tied to the year?
Maybe you want them reflected as two six month periods starting with the inclusive input date.
(Ie if input date was 15th Sept, it would be 1/7/11, 31/12/11, 1/1/12, 30/6/12?

So be a little more precise and succinct in the question please.

(Also note that there are Leap Years to consider when ''doing dates'', so it is not just a matter of adding x amount of days).


这篇关于通过datetime func获得4个日期的frm当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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