Skip to content

Commit 8bf721e

Browse files
committed
增加 String 转 NSDate 扩展方法
1 parent b070343 commit 8bf721e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// String+Ext.swift
3+
// ruby-china-ios
4+
//
5+
// Created by 柯磊 on 16/10/9.
6+
// Copyright © 2016年 ruby-china. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension String {
12+
func dateValue(format: String) -> NSDate? {
13+
let dateFormatter = NSDateFormatter()
14+
dateFormatter.dateFormat = format
15+
return dateFormatter.dateFromString(self)
16+
}
17+
18+
func dateValueFromISO8601() -> NSDate? {
19+
return self.dateValue("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
20+
}
21+
}

0 commit comments

Comments
 (0)