Skip to content

Instantly share code, notes, and snippets.

@srmds
Created October 2, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srmds/c541b0f0a94267777383 to your computer and use it in GitHub Desktop.
Save srmds/c541b0f0a94267777383 to your computer and use it in GitHub Desktop.
Swift 2.0 DateFormatter - Parse NSDate to a formatted String, Parse String to a formatted NSDate object
//
// DateFormatter.swift
// CoreDataCRUD
//
// Created by c0d3r on 01/10/15.
// Copyright © 2015 io pandacode. All rights reserved.
//
import Foundation
class DateFormatter {
class func getDateFromString(dateString:String, dateFormat:String = "dd-MM-yyyy") -> NSDate {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = dateFormat
return dateFormatter.dateFromString(dateString)!
}
class func getStringFromDate(date:NSDate, dateFormat:String = "dd-MM-yyyy") -> String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = dateFormat
return dateFormatter.stringFromDate(date)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment