简化iOS中的NSDate操作:NVDate

jopen 11年前

NVDate是一个用于处理iOS开发中NSDate操作的库。

NVDate拥有许多帮助您解决问题的功能。

  • 能够做很多日期操作任务
  • 用户友好的命名约定
  • 连环调用功能
  • 易于使用
  • 开源

简单示例

Full date of today

NVDate *date = [[NVDate alloc] initUsingToday];  NSLog(@"today is : %@", [date stringValue]);    // today is : Wednesday, February 5, 2014, 4:56:35 PM Western Indonesia Time

Last day's date of next 2 months

NVDate *date = [[NVDate alloc] initUsingToday];  [date nextMonths:2];  [date lastDayOfMonth];  NSLog(@"next 2 months from today is : %@", [date stringValueWithFormat:@"dd-MM-yyyy"]);    // next 2 months from today is : 30-04-2014

Second week of 2 months ago

NVDate *date = date = [[[[[NVDate alloc] initUsingToday] previousMonths:2] firstDayOfMonth] nextWeek];  date.dateFormatUsingString = @"yyyy-MM-dd HH:mm:ss";  NSLog(@"second week of 2 months ago is : %@", [date stringValue]);    // second week of 2 months ago is : 2013-12-08 17:03:36

Detect if yesterday is friday

BOOL isFriday = [[[[NVDate alloc] initUsingToday] previousDay] isCurrentDayName:NVDayUnitFriday];  NSLog(@"is yesterday was friday ? %@", isFriday ? @"yes" : @"no");    // is yesterday was friday ? no

项目主页:http://www.open-open.com/lib/view/home/1395109183478