1. 加减月份

-(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(int)month
{
    NSDateComponents *comps = [[NSDateComponents alloc] init];
   
    [comps setMonth:month];
   
    NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
   
    NSDate *mDate = [calender dateByAddingComponents:comps toDate:date options:0];
   
    return mDate;
   
}
 
2. 对日期进行排序
 // 对日期进行排序
    NSDateFormatter *dateFormatter = [NSDateFormatter new];
    dateFormatter.dateFormat = @"yyyy年MM月dd日";
    _dataArray = [_dataPlanArray sortedArrayUsingComparator:^(NSString *string1, NSString *string2) {
        NSDate *date1 = [dateFormatter dateFromString:string1];
        NSDate *date2 = [dateFormatter dateFromString:string2];
       
        return [date1 compare:date2];
    }];
 
 
3. 时间戳转化为特定的字符串
+(NSString *)stringWithTimestamp:(NSTimeInterval)tt format:(NSString *)format
{
     NSDate *date = [NSDate dateWithTimeIntervalSince1970:tt];
     NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
     [formatter setDateFormat:format];
     return [formatter stringFromDate:date];
}
 
4. 时间转时间戳

NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]];

NSLog(@"timeSp:%@",timeSp); //时间戳的值

关于 IOS 时间的一下用法的更多相关文章

  1. iOS 时间类经常用法

    //当前日前日期 NSDate *today = [NSDate date]; //时区 NSTimeZone *zone = [NSTimeZone systemTimeZone]; //设置间隔 ...

  2. iOS时间问题

    在iOS开发中,经常会遇到各种各样的时间问题,8小时时差,时间戳,求时间间隔,农历等等.解决办法网上比比皆是,但大多零零散散,很多资料并没有说明其中问题.这里集中总结一下,以便于以后查阅和供大家参考. ...

  3. C中的时间函数的用法

    C中的时间函数的用法    这个类展示了C语言中的时间函数的常用的用法. 源代码: #include <ctime>#include <iostream> using name ...

  4. ios多线程-GCD基本用法

    ios中多线程有三种,NSTread, NSOperation,GCD 这篇就讲讲GCD的基本用法 平时比较多使用和看到的是: dispatch_async(dispatch_get_global_q ...

  5. IOS时间格式转换

    在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理. 例如:如何将格式为“12-May-14 05.08.02.000000 PM” ...

  6. iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)

    1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...

  7. iOS block-base 动画简单用法+关键帧动画设置线性变化速度的问题

    本文转载至 http://www.tuicool.com/articles/aANBF3m 时间 2014-12-07 20:13:37  segmentfault-博客原文  http://segm ...

  8. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  9. iOS 时间的处理

    做App避免不了要和时间打交道,关于时间的处理,里面有不少门道,远不是一行API调用,获取当前系统时间这么简单.我们需要了解与时间相关的各种API之间的差别,再因场景而异去设计相应的机制. 时间的形式 ...

随机推荐

  1. ASP.NET MVC利用PagedList分页(一)

    前几天看见博客园上有人写ASP.NET MVC的分页思想,这让我不禁想起了PagedList.PagedList是NuGet上提供的一个分页的类库,能对任何IEnumerable<T>进行 ...

  2. dbms_redefinition在线重定义表结构

    dbms_redefinition在线重定义表结构 (2013-08-29 22:52:58) 转载▼ 标签: dbms_redefinition 非分区表转换成分区表 王显伟 在线重定义表结构 在线 ...

  3. bean的实例化方式

    spring中bean的实例化方式有三种,1.构造器实例化,2.实例工厂实例化,3.静态工厂实例化 1.构造器实例化方式 public class bean1 { public bean1() { } ...

  4. 「LibreOJ Round #6」花火

    转化思维的好题! 链接:here 大致题意: 有$ n$个数字,你每次可以交换相邻两个,还有一次交换任意两个元素的机会,求最少的交换次数使得这些数字升序排序(原数列两两不同) $ solotion:$ ...

  5. jq的遍历关系元素方法集合

    children .children(selector) 返回被选元素的所有直接子元素,不返回文本节点: 下面例子:给level-2的子元素设置border.比较使用children和find htm ...

  6. ASP.NET MVC - 多国语言的简单实现

    定义一个类 public class Book {     public int ID { get; set; }     public string Title { get; set; }      ...

  7. [转载]tmux常用快捷键

    Hello World 窗口管理只是 tmux 功能的一小部分,另一个很有用的功能就是,连接到远程主机之后,一旦断开,那么当前账户登录的任务就被取消了,但是使用 tmux 可以在断开之后继续工作,下次 ...

  8. swap扩展

    没有独立的分区,本地回环设备(使用软件来模拟实现硬件) 创建一个镜像文件 https://blog.csdn.net/linuxnews/article/details/51271875 有独立的分区

  9. android checkBox setTextColor无效

    代码中动态设置checkBox的文字选中背景和未选中背景,用如下代码: checkView.setTextColor(getResources().getColor(R.color.item_colo ...

  10. 引入第三方SDK allowBackup value不一致引起的编译异常

    项目中要引入一个客服的SDK,项目中 <application android:name=".AppApplication" android:allowBackup=&quo ...