Giter VIP home page Giter VIP logo

afdatehelper's Introduction

AFDateHelper

Version License Platform

A convenience extension for NSDate in Swift 1.2

Sample Project Screenshot

Usage

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

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))

// Date from ISO8601(Year & Month) String
NSDate(fromString:  "2009-08", format: .ISO8601(nil))

// Date from ISO8601(Date) String
NSDate(fromString:  "2009-08-11", format: .ISO8601(nil))

// Date from ISO8601(Date & Time) String
NSDate(fromString:  "2009-08-11T06:00-07:00", format: .ISO8601(nil))

// Date from ISO8601(Date & Time & Sec) String
NSDate(fromString:  "2009-08-11T06:00:00-07:00", format: .ISO8601(nil))

// Date from ISO8601(Date & Time & MilliSec) String
NSDate(fromString: "2009-08-11T06:00:00.000-07:00", format: .ISO8601(nil))

// 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

Comparing Dates

date.isEqualToDate(date) -> Bool
date.isToday() -> Bool  
date.isTomorrow()-> Bool
date.isYesterday() -> Bool
date.isSameWeekAsDate(date) -> Bool
date.isThisWeek() -> Bool
date.isNextWeek() -> Bool
date.isLastWeek() -> Bool
date.isSameYearAsDate(date) -> Bool
date.isThisYear() -> Bool
date.isNextYear() -> Bool
date.isLastYear() -> Bool

Adjusting Dates

date.dateByAddingDays(2) -> NSDate
date.dateBySubtractingDays(4) -> NSDate
date.dateByAddingHours(2) -> NSDate
date.dateBySubtractingHours(4) -> NSDate
date.dateByAddingMinutes(2) -> NSDate
date.dateBySubtractingMinutes(4) -> NSDate
date.dateAtStartOfDay() -> NSDate
date.dateAtEndOfDay() -> NSDate
date.dateAtStartOfWeek() -> NSDate
date.dateAtEndOfWeek() -> NSDate

Time Interval Between Dates

date.minutesAfterDate(now) -> Int
date.minutesBeforeDate(now) -> Int
date.hoursAfterDate(now) -> Int
date.hoursBeforeDate(now) -> Int
date.daysAfterDate(now) -> Int
date.daysBeforeDate(now) -> Int

Decomposing Dates

date.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.firstDayOfWeek() -> Int
date.lastDayOfWeek() -> Int
date.isWeekday() -> Int
date.isWeekend() -> Int

To String

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

Components To String

date.weekdayToString() -> String
date.shortWeekdayToString() -> String
date.veryShortWeekdayToString() -> String
date.monthToString() -> String
date.shortMonthToString() -> String
date.veryShortMonthToString() -> String

Requirements

Swift 1.2

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.

afdatehelper's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.