'Convert string date value to date with current time
When Convert string formate date value into Date type, the timezone always set to 12:00 AM How to set to current time of device, when convert "2021-12-04" to date ?
func stringToDateConvertion(date: String, format: String) -> Date {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.init(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone.init(abbreviation: "UTC")
dateFormatter.dateFormat = format
if let startDate = dateFormatter.date(from: dateStr) {
return startDate as Date
}
return Date() as Date
}
let dateValue = "2021-12-04"
stringToDateConvertion(date:dateString, format: "YYYY-MM-dd")
Result dataString value is
2021-12-04 00:00:00 +0000
- timeIntervalSinceReferenceDate : 660268800.0
How to show current time value "04:37:39 +0000" post fix to date value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
