[스위프트3] DateString을 기존 format에서 새로운 format으로 변경
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
|
/**
- parameters:
- date: 데이트형식의 String
- format1 : date파라미터의 Date Format
- format2 : date파라미터가 변경될 Format
- returns: format2로 바뀐 Date String
*/
static func dateFormatChange(date:String, format1:String, format2:String) -> String{
let format_1:DateFormatter = DateFormatter()
format_1.locale = Locale(identifier: "ko_KR")
format_1.dateFormat = format1
let format_2:DateFormatter = DateFormatter()
format_2.locale = Locale(identifier: "ko_KR")
format_2.dateFormat = format2
var second = ""
if format2 == "yyyyMMddHHmmss" {
format_2.dateFormat = "yyyyMMddHHmm"
let format_3:DateFormatter = DateFormatter()
format_3.dateFormat = "ss"
format_3.locale = Locale(identifier: "ko_KR")
second = format_3.string(from: Date())
}
return format_2.string(from: (format_1.date(from: date))!) + second
}
| cs |
댓글
댓글 쓰기