zoukankan      html  css  js  c++  java
  • 判断日期是今天昨天明天

    这个主要是从网上看到的 感觉非常好打算保存起来

    -(NSString *)compareDate:(NSDate *)date{

        NSTimeInterval secondsPerDay = 24 * 60 * 60;
        NSDate *today = [[NSDate alloc] init];
        NSDate *tomorrow, *yesterday;

        tomorrow = [today dateByAddingTimeInterval: secondsPerDay];
        yesterday = [today dateByAddingTimeInterval: -secondsPerDay];

    // 10 first characters of description is the calendar date:
        NSString * todayString = [[today description] substringToIndex:10];
        NSString * yesterdayString = [[yesterday description] substringToIndex:10];
        NSString * tomorrowString = [[tomorrow description] substringToIndex:10];

        NSString * dateString = [[date description] substringToIndex:10];

        if ([dateString isEqualToString:todayString])
        {
            return @"今天";
        } else if ([dateString isEqualToString:yesterdayString])
        {
            return @"昨天";
        }else if ([dateString isEqualToString:tomorrowString])
        {
            return @"明天";
        }
        else
        {
            return dateString;
        }
    }

  • 相关阅读:
    F. Journey
    D. Divide
    C. Counting Pair
    A. A Big Dinner
    E
    D -Sale
    第十三课 历史记录画笔工具
    第十二课 文字工具
    第十一课 模糊工具、海绵工具、仿制图章工具
    第十课 切片工具 修复画笔工具 修补工具 颜色替换工具
  • 原文地址:https://www.cnblogs.com/liumingxin123/p/5580369.html
Copyright © 2011-2022 走看看