NSDate 的一些操作

nc6433的头像 nc6433 11 2014-12-31 11:45 0


× 1   

浏览数: 4384

分享时间: 4 年 前


NSDate *date = [NSDate date];  


        NSTimeInterval a_day = 24*60*60;

        NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:a_day];


    NSTimeInterval a_day = 24*60*60;  
    NSDate *date = [NSDate date];  
    NSDate *tomorrow = [date addTimeInterval: date];  


   BOOL isEqual = [date isEqualToDate:tomorrow];  


NSDate *earlier_date = [tomorrow earlierDate:date];  
  NSLog(@"earlierDate  = %@",earlierDate); 


    NSDate *laterDate = [tomorrow laterDate:date];  
    NSLog(@"laterDate  = %@",laterDate);  


    NSTimeInterval secondsInterval= [date timeIntervalSinceDate:tomorrow];  
    NSLog(@"secondsInterval=  %lf",secondsInterval);  


    NSDateComponents *comps = [[NSDateComponentsalloc]init];  
    [comps setMonth:01];  
    [comps setDay:31];  
    [comps setYear:2013];  
    NSCalendar *calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];  
    NSDate *date = [calendar dateFromComponents:comps];  


    unsigned units  = NSMonthCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit;  
    NSDateComponents *_comps = [calendar components:units fromDate:date];  
    NSInteger month = [_comps month];  
    NSInteger year = [_comps year];  
    NSInteger day = [_comps day];  
    NSDateFormatter *formatter = [[NSDateFormatteralloc]init];  
    [formatter setDateStyle:NSDateFormatterFullStyle];//直接输出的话是机器码  
    //或者是手动设置样式[formatter setDateFormat:@"yyyy-mm-dd"];  
    NSString *dateString = [formatter stringFromDate:date];  
    NSLog(@"dateString = %@",dateString);  
    NSLog(@"formater = %@",formatter);  


- (NSDateFormatter *)getDateFormatter {  
    if (dateFormatter == nil) {  
    dateFormatter = [[NSDateFormatter alloc] init];  
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];  
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];  
    return dateFormatter;  

12 3 4 [下一页]

  • jopen的头像 jopen 2014-12-31 14:47 代码数:1016
  • ossaa的头像 ossaa 2018-10-17 16:23 代码数:0

    I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.

    Enjoy Mexico Villa Rentals in Cabo San Lucas

  • pevahanifo的头像 pevahanifo 2018-08-27 20:20 代码数:0

    I was looking at some of your posts on this website and I conceive this web site is really instructive! Keep putting up.. Luxury used cars

  • ossaa的头像 ossaa 2018-10-18 15:08 代码数:0

    I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.


  • ossaa的头像 ossaa 2018-10-20 20:05 代码数:0

    I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.

    The Hyde

  • pevahanifo的头像 pevahanifo 2018-08-29 18:39 代码数:0

    This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information...Edmonton Plumbing

  • tiexinliu的头像 tiexinliu 2015-02-26 14:23 代码数:0
  • jhoneila的头像 jhoneila 2018-12-22 15:56 代码数:0

    You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!. CPR Classes Tucson

  • ossaa的头像 ossaa 2018-09-01 17:20 代码数:0

    Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’t wait to read more posts.  leilao imoveis

  • ossaa的头像 ossaa 2018-09-03 16:08 代码数:0

    Thanks for the post and great tips..even I also think that hard work is the most important aspect of getting success.. lisina herpes