File tree Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -36,10 +36,12 @@ public extension Date {
36
36
/// - format: Date format (ex: "yyyy mm dd")
37
37
/// default: yyyy mm dd
38
38
/// - locale: locale identifier, default "it_IT"
39
+ /// - timezone: timezone identifier, default: "UTC"
39
40
/// - Returns: a string from date
40
- public func string( dateFormat format: String ? = " yyyy MM dd " , locale: String = " it_IT " ) -> String {
41
+ public func string( dateFormat format: String ? = " yyyy MM dd " , locale: String = " it_IT " , timezone : String = " UTC " ) -> String {
41
42
let dateFormatter = DateFormatter ( )
42
43
dateFormatter. locale = Locale ( identifier: locale)
44
+ dateFormatter. timeZone = TimeZone ( identifier: timezone)
43
45
dateFormatter. dateFormat = format
44
46
return dateFormatter. string ( from: self )
45
47
}
Original file line number Diff line number Diff line change @@ -93,6 +93,6 @@ class DateTests: XCTestCase {
93
93
}
94
94
95
95
let dateString = date. string ( dateFormat: " yyyy MM dd HH:mm:ss " )
96
- XCTAssertEqual ( dateString, " 2017 11 17 12 :55:02 " )
96
+ XCTAssertEqual ( dateString, " 2017 11 17 11 :55:02 " )
97
97
}
98
98
}
You can’t perform that action at this time.
0 commit comments