MCDateExtensions 1.0.0

MCDateExtensions 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 BSD 3.0
发布最新版本2014年12月

Mirego维护。



  • Mirego, Inc.

MCDateExtensions - 与 NSDate一起享受乐趣。

#import "NSDate+MCExtensions.h"

- (void)funWithMCDateExtensions
{
  NSDate* today = [NSDate date];

  // Today? Tomorrow? Yesterday?
  [today isToday]; // returns YES
  [today isYesterday]; // returns NO
  [today isTomorrow]; // returns NO

  // Compare based on day
  [today isSameDayAsDate:[NSDate date]]; // Most likely returns YES

  // Get all the details of a date
  NSDateComponents* todayBrokenDown = [today components];
  // ...with specific units
  NSDateComponents* specificUnits = [today componentsWithUnits:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)];

  // Some fun Maths!
  NSDate* sameDayNextYear = [today dateByAddingYears:1];
  NSDate* sameDayNextQuarter = [today dateByAddingQuarters:1];
  NSDate* sameDayInTwoMonth = [today dateByAddingMonths:2];
  NSDate* sameDayNextWeek = [today dateByAddingWeeks:1];
  NSDate* yesterday = [today dateByAddingDays:-1];
  NSDate* tomorrow = [today dateByAddingHours:24];
  NSDate* nextHour = [today dateByAddingMinutes:60];
  NSDate* inTwoMinutes = [today dateByAddingSeconds:120];
  NSDate* inAFewSeconds = [today dateByAddingCalendarUnit:(NSSecondCalendarUnit) value:30];

  // Differences
  NSInteger days = [NSDate daysBetweenDate:today andDate:tomorrow]; // returns 1
  NSInteger weeks = [NSDate daysBetweenDate:today andDate:sameDayNextWeek]; // returns 1
  NSInteger months = [NSDate monthsBetweenDate:today andDate:sameDayInTwoMonth]; // returns 2
  NSInteger years = [NSDate monthsBetweenDate:today andDate:sameDayNextYear]; // returns 1
}

添加到您的项目

如果您使用 CocoaPods,这非常简单。将以下内容添加到您的 Podfile 并运行 pod install

pod 'MCDateExtensions', :git => 'https://github.com/mirego/MCDateExtensions.git'

不要忘记在需要的地方 #import "NSDate+MCExtensions.h"

许可证

MCDateExtensions 由 © 2013 Mirego 所有,可以在 新 BSD 许可证下自由分发。查看 LICENSE.md 文件。

关于 Mirego

Mirego 是一群充满激情的人组成的团队,他们相信工作是一个你可以创新和享受快乐的地方。我们自豪地为 iPhoneiPadAndroidBlackberryWindows PhoneWindows 8 开发了移动应用。在 life.mirego.com 了解更多关于我们的团队信息。