NsharpDate

NSharpDate is a category for the NSDate class that adds a few properties and methods.

How To Get Started

  1. Download Start of by *download *and extract NsharpDate from Github

  2. Add NSHarpDate to your project Add NSDate+NSharpDate.h and NSDate+NSharpDate.m to your project

  3. Import the category Add this line to the top of the class where you want to use NSharpDate:#import "NSDate+NSharpDate.h"

Installation with CocoaPods

NsharpDate methods

stringByFormat:

Parameters

a string representing what format you want the returning nsstring to look like

Example

NSDate *date = [NSDate date];
NSString *dateString = [date stringByFormat:@"yyyy-MM-dd"];

returns:

2012-05-27

stringByLongDateFormat

Example

NSDate *date = [NSDate date];
NSString *dateString = [date stringByLongDateFormat];

returns:

IOS Device set to English locale: Sunday, May 27, 2012
IOS Device set to Swedish locale: söndag 27 maj 2012

stringByLongTimeFormat

Example

NSDate *date = [NSDate date];
NSString *dateString = [date stringByLongTimeFormat];

returns:

IOS Device set to English locale: 6:22:09 PM Central European Summer time
IOS Device set to Swedish locale: kl 18:22:09 Centraleuropa, sommartid

stringByShortTimeFormat

Example

NSDate *date = [NSDate date];
NSString *dateString = [date stringByShortTimeFormat];

returns:

IOS Device set to English locale: 6:22:09 PM
IOS Device set to Swedish locale: 18:22:06

monthsSince

Example

NSDate *date = [NSDate date];
NSDate *dateTwoMonthsAgo = [date newDateByAddingMonths:-2];
NSInteger monthsSince = [date monthsSince:dateInThreeMonths];

returns:

2

monthsTo

Example

NSDate *date = [NSDate date];
NSDate *dateInThreeMonths = [date newDateByAddingMonths:3];
NSInteger monthsTo = [date monthsTo:dateTwoMonthsAgo];

returns:

3

Properties

Day

Example

NSDate *date = [NSDate date]; NSInteger day = date.Day;

returns:

The Day property returns a NSInteger containing the current date's day. For example: 27

DayOfWeek

Example

NSDate *date = [NSDate date]; NSString *day = date.DayOfWeek;

returns:

IOS Device set to English locale: Sunday
IOS Device set to Swedish locale: Söndag

DayOfYear

Example

NSDate *date = [NSDate date]; NSString *day = date.DayOfYear;

returns:

The DayOfYear property returns a NSInteger containing the current date's day of year. For example: 148

Hour

Example

NSDate *date = [NSDate date]; NSString *day = date.Hour;

returns:

The Hour property returns a NSInteger containing the current date's hour. For example: 18

Milliseconds

Example

NSDate *date = [NSDate date]; NSString *day = date.Milliseconds;

returns:

The Milliseconds property returns a NSInteger containing your date's Milliseconds. For example: 991

Minute

Example

NSDate *date = [NSDate date]; NSString *day = date.Minute;

returns:

The Minute property returns a NSInteger containing your date's Minute. For example: 22

Month

Example

NSDate *date = [NSDate date]; NSString *day = date.Month;

returns:

The Month property returns a NSInteger containing your date's Month. For example: 5

Second

Example

NSDate *date = [NSDate date]; NSString *day = date.Second;

returns:

The Second property returns a NSInteger containing your date's Second. For example: 9