Latest 4.0.1
Homepage https://github.com/jjjjjeffrey/JDateExtention
License MIT
Platforms ios 8.0, requires ARC
Authors

AFDateHelper

Version
License
Platform

An NSDate Extension for Swift 2.0

Sample Project Screenshot

Usage

To run the example project, clone or download the repo, and run.

Creating Date from String

// Date from String with custom format
NSDate(fromString: "16 July 1972 6:12:00 ", format: .Custom("dd MMM yyyy HH:mm:ss")) -> NSDate
// Date from ISO8601(Year) String
NSDate(fromString:  "2009", format: .ISO8601(nil)) -> NSDate
// Date from ISO8601(Year & Month) String
NSDate(fromString:  "2009-08", format: .ISO8601(nil)) -> NSDate
// Date from ISO8601(Date) String
NSDate(fromString:  "2009-08-11", format: .ISO8601(nil)) -> NSDate
// Date from ISO8601(Date & Time) String
NSDate(fromString:  "2009-08-11T06:00-07:00", format: .ISO8601(nil)) -> NSDate
// Date from ISO8601(Date & Time & Sec) String
NSDate(fromString:  "2009-08-11T06:00:00-07:00", format: .ISO8601(nil)) -> NSDate
// Date from ISO8601(Date & Time & MilliSec) String
NSDate(fromString: "2009-08-11T06:00:00.000-07:00", format: .ISO8601(nil)) -> NSDate
// Date from DotNetJSON String
NSDate(fromString: "/Date(1260123281843)/", format: .DotNet) -> NSDate
// Date from RSS String
NSDate(fromString: "Fri, 09 Sep 2011 15:26:08 +0200", format: .RSS) -> NSDate
// Date from AltRSS String
NSDate(fromString: "09 Sep 2011 15:26:08 +0200", format: .AltRSS) -> NSDate -> NSDate

Creating Date

NSDate.jd_tomorrow() -> NSDate
NSDate.jd_yesterday() -> NSDate

Comparing Dates

date.isEqualToDate(date) -> Bool
date.jd_isToday() -> Bool  
date.jd_isTomorrow()-> Bool
date.jd_isYesterday() -> Bool
date.jd_isSameWeekAsDate(date) -> Bool
date.jd_isThisWeek() -> Bool
date.jd_isNextWeek() -> Bool
date.jd_isLastWeek() -> Bool
date.jd_isSameYearAsDate(date) -> Bool
date.jd_isThisYear() -> Bool
date.jd_isNextYear() -> Bool
date.jd_isLastYear() -> Bool

Adjusting Dates

date.jd_dateByAddingDays(2) -> NSDate
date.jd_dateBySubtractingDays(4) -> NSDate
date.jd_dateByAddingHours(2) -> NSDate
date.jd_dateBySubtractingHours(4) -> NSDate
date.jd_dateByAddingMinutes(2) -> NSDate
date.jd_dateBySubtractingMinutes(4) -> NSDate
date.jd_dateByAddingSeconds(90) -> NSDate
date.jd_dateBySubtractingSeconds(90) -> NSDate
date.jd_dateAtStartOfDay() -> NSDate
date.jd_dateAtEndOfDay() -> NSDate
date.jd_dateAtStartOfWeek() -> NSDate
date.jd_dateAtEndOfWeek() -> NSDate
date.jd_dateAtTheStartOfMonth() -> NSDate
date.jd_dateAtTheEndOfMonth() -> NSDate
date.jd_setTimeOfDate(hour: 6, minute: 30, second: 15) -> NSDate

Time Interval Between Dates

date.jd_secondsAfterDate(now) -> Int
date.jd_secondsBeforeDate(now) -> Int
date.jd_minutesAfterDate(now) -> Int
date.jd_minutesBeforeDate(now) -> Int
date.jd_hoursAfterDate(now) -> Int
date.jd_hoursBeforeDate(now) -> Int
date.jd_daysAfterDate(now) -> Int
date.jd_daysBeforeDate(now) -> Int

Decomposing Dates

date.jd_nearestHour() -> Int
date.year() -> Int
date.month() -> Int
date.week() -> Int
date.day() -> Int
date.hour() -> Int
date.minute() -> Int
date.seconds() -> Int
date.weekday() -> Int
date.nthWeekday() -> Int
date.monthDays() -> Int
date.jd_firstDayOfWeek() -> Int
date.jd_lastDayOfWeek() -> Int
date.jd_isWeekday() -> Int
date.jd_isWeekend() -> Int

To String

date.jd_toString() -> String
date.jd_toString(format: .Custom("dd MMM yyyy HH:mm:ss")) -> String
date.jd_toString(format: .ISO8601(ISO8601Format.Year)) -> String
date.jd_toString(format: .ISO8601(ISO8601Format.YearMonth)) -> String
date.jd_toString(format: .ISO8601(ISO8601Format.Date)) -> String
date.jd_toString(format: .ISO8601(ISO8601Format.DateTime)) -> String
date.jd_toString(format: .ISO8601(ISO8601Format.DateTimeSec)) -> String
date.jd_toString(format: .ISO8601(ISO8601Format.DateTimeMilliSec)) -> String
date.jd_toString(format: .DotNet) -> String
date.jd_toString(format: .RSS) -> String
date.jd_toString(format: .AltRSS) -> String
date.jd_toString(dateStyle: .ShortStyle, timeStyle: .NoStyle, doesRelativeDateFormatting: true) -> String
date.jd_toString(dateStyle: .ShortStyle, timeStyle: .NoStyle, doesRelativeDateFormatting: false) -> String
date.jd_toString(dateStyle: .MediumStyle, timeStyle: .ShortStyle, doesRelativeDateFormatting: false) -> String
date.jd_toString(dateStyle: .LongStyle, timeStyle: .LongStyle, doesRelativeDateFormatting: false) -> String
date.jd_toString(dateStyle: .FullStyle, timeStyle: .FullStyle, doesRelativeDateFormatting: false) -> String
date.jd_relativeTimeToString()

Components To String

date.jd_weekdayToString() -> String
date.jd_shortWeekdayToString() -> String
date.jd_veryShortWeekdayToString() -> String
date.jd_monthToString() -> String
date.jd_shortMonthToString() -> String
date.jd_veryShortMonthToString() -> String

Requirements

Swift 2.0

Installation

AFDateHelper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "AFDateHelper"

Author

Melvin Rivera, [email protected]

License

AFDateHelper is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "JDateExtention",
    "version": "4.0.1",
    "summary": "NSDate Extension for Swift 2.0",
    "description": "Extension for NSDate in Swift for creating, modifying or comparing dates.",
    "homepage": "https://github.com/jjjjjeffrey/JDateExtention",
    "license": "MIT",
    "authors": {
        "Melvin Rivera": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jjjjjeffrey/JDateExtention.git",
        "tag": "4.0.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "AFDateHelper/**/*"
}

Pin It on Pinterest

Share This