在特定日期增加1个月 [英] Adding 1 month to a specific date

查看:131
本文介绍了在特定日期增加1个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flex3.

我想知道如何获取下个月的当前日期.
我面临的问题是,如果我从日期字段中选择2011年3月31日,则无法获得2011年4月30日的结果.year年的2月存在相同的问题.所以请尽快给我帮助.

我希望如果我单击2012年1月31日,那么我得到的结果就像2012年2月29日.

我当前的代码是:


txtdate.text = da.getDate().toString();
txtmonth.text =(da.getMonth()+ 1).toString();
txtyear.text = da.getFullYear().toString();

var明天:日期=新日期(da.getFullYear(),(da.getMonth()+ 1),da.getDate());

电流输出是这样的

如果我在2011年3月17日通过,那么我会在2011年4月17日获得结果.
如果我在2011年1月31日通过,那么我在2011年3月3日得到结果.

I am using Flex 3.

I want to know that how to get the current date of the next month.
I am facing the problem that if i choose the 31st march, 2011 from datefield, i can''t get the result as 30th April, 2011. Same problem with the February Month of the leap year. So please give me help as early as possible.

I want that if i click on the 31st January, 2012 then i got result like 29th February, 2012.

My current code is:


txtdate.text = da.getDate().toString();
txtmonth.text = (da.getMonth()+1).toString();
txtyear.text = da.getFullYear().toString();

var tomorrow:Date = new Date(da.getFullYear(),(da.getMonth()+1) ,da.getDate());

Current output is like this

if i pass 17th March, 2011 then i got result 17th April, 2011.
if i pass 31st January, 2011 then i got result 3rd March, 2011.

推荐答案

从本质上讲,这不是编程问题.

您首先定义下个月的当前日期",然后立即自己证明不可能在每个给定的日期都找到.请意识到这是我想要但我不想要",仅此而已.自己决定想要什么.

如果您向您解释的不是纯粹的形式(没有意义),而是根据所需的UI行为,就可以轻松地提出这个问题.在这种情况下,您希望以恢复的理智"获得转变的想法.

—SA
This is not a programming question, in essence.

You first define "current date of the next month" and then immediately prove by yourself that it is not possible to find for every given date. Please realize that this is "I want it but I don''t want it" and nothing else. Decide for yourself what you want.

You could easily make this question if you explained you idea not it its pure form which does not make sense, but in terms of desired UI behavior, for example. In this case you would hope to get the transformed idea with "restored sanity".

—SA


这篇关于在特定日期增加1个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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