-
Notifications
You must be signed in to change notification settings - Fork 11
/
NSDateISO8601.swift
28 lines (23 loc) · 970 Bytes
/
NSDateISO8601.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// NSDateISO8601.swift
//
// Created by Justin Makaila on 8/11/14.
// Copyright (c) 2014 Present, Inc. All rights reserved.
//
import Foundation
public extension NSDate {
public class func ISOStringFromDate(date: NSDate) -> String {
var dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(abbreviation: "GMT")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
return dateFormatter.stringFromDate(date).stringByAppendingString("Z")
}
public class func dateFromISOString(string: String) -> NSDate {
var dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone.localTimeZone()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
return dateFormatter.dateFromString(string)
}
}