ios 获取n个月前或者n个月后的日期
NSCalendar *calendar = [NSCalendar currentCalendar];
NSRange range = [calendar rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
NSUInteger numberOfDaysInMonth = range.length;
NSDate *datetime = [NSDate dateWithTimeIntervalSince1970:csmcurrentTime-(86400*numberOfDaysInMonth * data_current_index)];
NSDateFormatter *dateformat = [[[NSDateFormatter alloc] init] autorelease];
[dateformat setDateFormat:@"yyyy年MM月"];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = nil;
comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:mydate];
NSDateComponents *adcomps = [[NSDateComponents alloc] init];
[adcomps setYear:0];
[adcomps setMonth:-1];
[adcomps setDay:0];
NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:mydate options:0];
ios 获取n个月前或者n个月后的日期的更多相关文章
- JavaScript时间处理之几个月前或几个月后的指定日期
在平常项目开发过程中,经常会遇到需要在JavaScript中处理时间的情况,无非两种(1,逻辑处理 2,格式转换处理).当然要说相关技术博,园子里闭着眼睛都能抓一把,但是我要做的是:既然有幸被我碰到 ...
- sqlserver获取当前id的前一条数据和后一条数据
一.条件字段为数值的情况 select * from tb where id=@id; --当前记录 select top 1 * from tb where id>@id order ...
- js获取几个月前,几周前时间。
/** * DK 命名空间 防止全局变量污染 */ var DK = {} ; /** * 获取前几个月,默认为一个月,当前时间 * @author duke * @date 格式为yy ...
- java 获取日期的几天前,几个月前和几年前
java 获取日期的几天前,几个月前和几年前. package bys.utils; import java.util.Date; /** * Created by toutou on 2015/3/ ...
- Oracle获取一周前,一个月前,一年前, 本周,本月,当年的日期
1.获取当前时间一周前的日期 ' day from dual 类似的 --当前时间减去7分钟的时间 ' MINUTE from dual --当前时间减去7小时的时间 ' hour from dual ...
- python 获取几小时之前,几分钟前,几天前,几个月前,及几年前的具体时间
引入以下两个包: import datetime import arrow 具体代码 # import datetime # import arrow def getTime(self, flag,d ...
- php获取当前月份的前(后)几个月
//获取当前月份的前一月 function GetMonth($sign) { //得到系统的年月 $tmp_date=date("Ym"); //切割出年份 $tmp_year= ...
- php获取一个月前的时间戳,获取三个月前的时间戳,获取一年前的时间戳
strtotime 非常强大的一个获取时间戳的函数 php获取一个月前的时间戳: strtotime("-0 year -1 month -0 day"); php获取三个月前的时 ...
- Java中常用的获取从当前月开始的前第i个月、取结束时间与开始时间相差多少个月份等的方法
@RunWith(SpringRunner.class) @SpringBootTest public class DateTest { @Test public void test(){ DateF ...
随机推荐
- 开始认真学计算机网络----computer network学习笔记(一)
什么是计算机网络,就是连一堆计算机,计算机不单单指pc,还包括打印机啦,手机啦巴拉巴拉一堆 为什么要连,share data共享数据 数据? 文档,图片,视频,巴拉巴拉 网络有什么类型? LAN--- ...
- 1084. Broken Keyboard (20)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
- Percona-Xtrabackup 2.3.3 慢查询依旧堵塞MariaDB备份(三)
MariaDB [yoon]> select version();+---------------------+| version() |+---------------------+| 10. ...
- python中的多继承
python和C++一样,支持多继承.概念虽然容易,但是困难的工作是如果子类调用一个自身没有定义的属性,它是按照何种顺序去到父类寻找呢,尤其是众多父类中有多个都包含该同名属性. class P1 #( ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- 用js进行日期的加减
如题,开始查了查js的使用文档,但没发现可以直接用的函数,于是就想自己写函数来着,这就要涉及到每个月天数的判断,如果是2月份的话,还要涉及到闰年的判断,虽然不复杂但我想js应该不会这么低级,于是查了下 ...
- 基于perl的网络爬虫
use Mojo::UserAgent; use Bloom::Filter; use Smart::Comments; use DBI; my $dbname = "bbs_url&quo ...
- 【EF Code First】Migrations数据库迁移
1,打开工具->NuGet程序管理器->程序包管理器控制台 默认项目中要选择 数据访问上下文类 所在的项目 我的DB是在命名空间CodeFirst.UI下的所以选择CodeFirst. ...
- EntityFramwork(1) 源地址https://msdn.microsoft.com/zh-cn/data/jj193542
1.创建应用程序 简单起见,我们将构建一个使用 Code First 执行数据访问的基本控制台应用程序. 打开 Visual Studio "文件"->"新建&qu ...
- FPGA保留信号的语句
(*synthesis,keep*) (*synthesis,probe_port,keep *) 例:(*synthesis,probe_port,keep *) wire e; 可用于wire型和 ...