当前位置: 首页 > news >正文

38、当前时间是否在开放时间内(也就是时间对比)

  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    

    // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制

    

//    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

    [formatter setDateFormat:@"YYYY-MM-dd"];

    //现在时间,你可以输出来看下是什么格式

        NSDate *datenow = [NSDate date];

    //----------将nsdate按formatter格式转成nsstring

      NSString *nowtimeStr = [formatter stringFromDate:datenow];

       NSLog(@"nowtimeStr =  %@",nowtimeStr);

    NSString *startTime=@"2017-05-01";

     NSDate *startDate = [formatter dateFromString:startTime];

        NSString *endTime=@"2017-05-22";

         NSDate *endDate = [formatter dateFromString:endTime];

    [self checkDateBeginDate:startDate endDate:endDate];

 

//时间对比方法

- (NSInteger)checkDateBeginDate:(NSDate *)beginDate endDate:(NSDate *)endDate {

    /**

     NSTimeInterval timeInterval = [endDate timeIntervalSinceDate:beginDate];

     NSInteger days = timeInterval/(3600*24);

     NSLog(@"----days:----%ld",days);

     **/

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

    dateFormatter.dateFormat = @"yyyy-MM-dd";

    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];

    NSDate *currentDate = [dateFormatter dateFromString:currentDateStr];

    

    //当天日期小于结束日期并且当前日期大于开始时间

    if ([currentDate compare:endDate] == NSOrderedAscending&&[currentDate compare:beginDate] == NSOrderedDescending) {

     NSLog(@"该楼盘在销售时间范围内");

      }

       //起始日期大于截止日期

    if ([currentDate compare:endDate] == NSOrderedDescending) {

          NSLog(@"该楼盘已经过期");

    }

//    //起始日期与截止日期间隔不能大于3个月

//    if ([[beginDate dateByAddingTimeInterval:3*30*24*60*60] compare:endDate] == NSOrderedDescending) {

//        return 1;

//    }

//    //起始日期与截止日期间隔大于3个月

    return 0;

}

 *重要提示:

NSOrderedAscending的意思是:左边的操作对象小于右边的对象。

NSOrderedDescending的意思是:左边的操作对象大于右边的对象。

转载于:https://www.cnblogs.com/qiangzheVSruozhe/p/6893803.html

相关文章:

  • cocos2d-x2.2.5走四棋儿源代码“开源”
  • numpy之初探排序和集合运算
  • eclipse:刪除空行
  • HTTP权威指南-URL与资源
  • Android 自己定义RecyclerView 实现真正的Gallery效果
  • 数据传递-------@PathVariable
  • pragma once
  • 2017年5月27日
  • Mysql中key 、primary key 、unique key 与index区别
  • 空物体下很多子物体的体积判断并附加对应的碰撞器
  • http://www.onvif.org/onvif/ver20/util/operationIndex.html
  • Hadoop高速入门
  • 对象的初始化过程
  • C# goto
  • 《Java并发编程实战》第九章 图形用户界面应用程序界面 读书笔记
  • [nginx文档翻译系列] 控制nginx
  • 「前端早读君006」移动开发必备:那些玩转H5的小技巧
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • ES6之路之模块详解
  • JAVA 学习IO流
  • Java精华积累:初学者都应该搞懂的问题
  • JWT究竟是什么呢?
  • Mysql5.6主从复制
  • PermissionScope Swift4 兼容问题
  • Python_OOP
  • Vue2.0 实现互斥
  • 成为一名优秀的Developer的书单
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 解决iview多表头动态更改列元素发生的错误
  • 你真的知道 == 和 equals 的区别吗?
  • 微服务框架lagom
  • 赢得Docker挑战最佳实践
  • 用quicker-worker.js轻松跑一个大数据遍历
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • 长三角G60科创走廊智能驾驶产业联盟揭牌成立,近80家企业助力智能驾驶行业发展 ...
  • 浅谈sql中的in与not in,exists与not exists的区别
  • # Pytorch 中可以直接调用的Loss Functions总结:
  • #13 yum、编译安装与sed命令的使用
  • #LLM入门|Prompt#1.7_文本拓展_Expanding
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (cljs/run-at (JSVM. :browser) 搭建刚好可用的开发环境!)
  • (Matlab)使用竞争神经网络实现数据聚类
  • (Oracle)SQL优化技巧(一):分页查询
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (二)fiber的基本认识
  • (附源码)spring boot智能服药提醒app 毕业设计 102151
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (六) ES6 新特性 —— 迭代器(iterator)
  • (转)创业家杂志:UCWEB天使第一步
  • (转载)微软数据挖掘算法:Microsoft 时序算法(5)
  • *(长期更新)软考网络工程师学习笔记——Section 22 无线局域网
  • .cn根服务器被攻击之后
  • .htaccess 强制https 单独排除某个目录