zoukankan      html  css  js  c++  java
  • IOS managerTime

      1. NSString ->NSdate

            NSString *birthday =  self.btnBirthday.titleLabel.text;

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

            [dateFormatter setDateFormat:@"yyyy-MM-dd"];

            NSDate *date = [dateFormatter dateFromString:birthday];

          2.getcurrent time

         #pragma  mark - 获取当前时间

         -(NSDate *)getcurTime{

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

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

         //NSString *dataTime = [formatter stringFromDate: [NSDate date]];//NsDate转Nsstring

         return  [NSDate date];

         }

        3.compareTime

         -(int)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay

        {

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

        [dateFormatter setDateFormat:@"yyyy-MM-dd"];

        NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];

        NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];

        NSDate *dateA = [dateFormatter dateFromString:oneDayStr];

        NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];

        NSComparisonResult result = [dateA compare:dateB];

        NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay);

        if (result == NSOrderedDescending) {

            //NSLog(@"Date1  is in the future");

            return 1;

        }

        else if (result == NSOrderedAscending){

            //NSLog(@"Date1 is in the past");

            return -1;

        }

        //NSLog(@"Both dates are the same");

        return 0;

        

      }

          

  • 相关阅读:
    Nginx如何配置基础缓存
    Websocket消息过长自动断开连接?
    Docker错误删除Postgresql容器如何恢复?
    Docker安装带中文全文搜索插件zhparser的Postgresql数据库
    Postgresql数据库安装中文全文搜索插件zhparser的问题
    Presto通过RESTful接口新增Connector
    在windows的IDEA运行Presto
    Druid.io通过NiFi摄取流数据
    Druid.io SQL乱码问题
    Druid.io启用SQL支持
  • 原文地址:https://www.cnblogs.com/HQBBOX/p/5286594.html
Copyright © 2011-2022 走看看