Created
October 2, 2015 13:57
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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