码迷,mamicode.com
首页 > 移动开发 > 详细

IOS managerTime

时间:2016-03-17 12:38:42      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

  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;

    

  }

 

      

IOS managerTime

标签:

原文地址:http://www.cnblogs.com/HQBBOX/p/5286594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!