如何制作包含天数的另一个数组 [英] how to make another array containing number of days remain
本文介绍了如何制作包含天数的另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数组如下所示
_combinedBirthdates(
"03/12/2013",
"03/12/2013",
"08/13/1990",
"12/09/1989",
"02/06",
"09/08",
"03/02/1990",
"08/22/1989",
"03/02",
"05/13",
"10/16",
"07/08",
"08/31/1990",
"04/14/1992",
"12/15/1905",
"08/14/1989",
"10/07/1987",
"07/25",
"07/17/1989",
"03/24/1987",
"07/28/1988",
"01/21/1990",
"10/13"
)
所有元素都是上面的NSString
NSArray
。
如何制作另一个包含数量的数组特定日期的剩余天数
这样的事情
How can I make another array which contains number of days remain for particular date something like this
_newlymadeArray(
"125",
"200",
"50",
"500",
"125",
and so on
)
推荐答案
使用此算法:
- 获取当前的y
- 将数组中的每个日期转换为当前年份的日期。例如,03/02/1990变为03/02/2013
- 如果步骤2的日期早于当前日期,则将其年份提前一(即 03/02/2013成为03/02/2014)
- 使用中的技术这个问题,找到第3步之前的天数。它将少于一年中的天数。
- Obtain the current year
- Convert each date from your array to a date in the current year. For example, "03/02/1990" becomes "03/02/2013"
- If the date from the step 2 is before the current date, advance its year by one (i.e. "03/02/2013" becomes "03/02/2014")
- Using a technique from this question, find the number of days till the date from step 3. It will be less than the number of days in a year.
这篇关于如何制作包含天数的另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文