Latest 1.0.0
Homepage https://github.com/ltebean/LTSwiftDate
License MIT
Platforms ios 8.0, requires ARC
Authors

LTSwiftDate

Installation

pod 'LTSwiftDate'

How to use

NSDate & String conversion

NSDate to String

let time = Date().toString(format: "MM/dd/yyyy") //  04/08/2016
let time = Date().toString(format: "MMM d, H:mm a") //  Apr 8, 8:29 AM

String to NSDate

"04/08/2016".toDate(format: "MM/dd/yyyy")

You can find the complete reference for the format string here: http://nsdateformatter.com/

NSDate operation

LTSwiftDate adds exension on Int to generate date components, it supports:

  • seconds
  • minutes
  • hours
  • days
  • weeks
  • years

Example:

let now = Date()
let nextMinute = now + 1.minutes
let yesterday = now - 1.days
let lastMonth = now - 1.months
...

Date comparison

You can compare dates using:

  • >
  • >=
  • ==
  • <
  • <=
  • isEqualToDate

Example:

let now = Date()
let tomorror = now + 1.days
if (now < tomorrow) {
  ...
}

now.isEqual(toDate: now + 1.mins, ignoreTime=true) // true

Date shortcut

let now = Date()
let startOfDay = now.startOfDay()
let endOfDay = now.endOfDay()

Date caculation

let now = Date()
let tomorrow = now + 1.days
let days = now.daysBeforeDate(tomorrow) // days will be 1

Latest podspec

{
    "name": "LTSwiftDate",
    "version": "1.0.0",
    "summary": "Easy-to-use NSDate operation",
    "homepage": "https://github.com/ltebean/LTSwiftDate",
    "license": "MIT",
    "authors": {
        "ltebean": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ltebean/LTSwiftDate.git",
        "tag": "v1.0.0"
    },
    "source_files": "LTSwiftDate/LTSwiftDate.swift",
    "requires_arc": true,
    "platforms": {
        "ios": "8.0"
    }
}

Pin It on Pinterest

Share This