Implemented the "dateOnly" and "dateAndTime" static formatter in the DateFormatter+Formatter extension.
This commit is contained in:
parent
267083726b
commit
bfc231b5ec
34
Sources/Extensions/DateFormatter+Formatter.swift
Normal file
34
Sources/Extensions/DateFormatter+Formatter.swift
Normal file
@ -0,0 +1,34 @@
|
||||
import Foundation
|
||||
|
||||
extension DateFormatter {
|
||||
|
||||
// MARK: Formatters
|
||||
|
||||
static let dateOnly = {
|
||||
let formatter = DateFormatter()
|
||||
|
||||
formatter.timeZone = .init(secondsFromGMT: 0)
|
||||
formatter.dateFormat = .Format.yearMonthDay
|
||||
|
||||
return formatter
|
||||
}()
|
||||
|
||||
static let dateAndTime = {
|
||||
let formatter = DateFormatter()
|
||||
|
||||
formatter.timeZone = .init(secondsFromGMT: 0)
|
||||
formatter.dateFormat = .Format.dateAndTimeWithMicroseconds
|
||||
|
||||
return formatter
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Format
|
||||
|
||||
private extension String {
|
||||
enum Format {
|
||||
static let yearMonthDay = "yyyy-MM-dd"
|
||||
static let dateAndTimeWithMicroseconds = "yyyy-MM-dd'T'HH:mm:ss.SSS"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user