I'm using EVReflection and Date does not work. And with NSDate I don't know how to format to string like 'dd-MM-yyyy HH:mm'.
2 Answers
Two things:
First: You need to ask a specific question, always with Code similar to, or the actual code that shows what you're trying to acomplish.. None of these are here.
Second:
What you are trying to do is not possible unfortunately. Looking at EVReflection, it's property setter .setObjectForKey
doesn't work with structs, and if you look at the Title of the page of Date
in the apple docs.. it is a struct. Do your research!
EVReflection suggests :
Instead of using a struct, create your own object model for that struct
So you'll have to try that, and see if it works.
As for your NSDate format, use an extension like this one found in this post here:
extension Date {
var currentUTCTimeZoneDate: String {
let formatter = DateFormatter()
formatter.timeZone = TimeZone(identifier: "UTC")
formatter.amSymbol = "AM"
formatter.pmSymbol = "PM"
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return formatter.string(from: self)
}
}
Which you can use on NSDate:
extension NSDate {
var currentUTCTimeZoneDate: String {
return (self as Date).currentUTCTimeZoneDate
}
}
let d = NSDate().currentUTCTimeZoneDate
print(d) // prints 2017-07-07 22:19:22

- 1,050
- 8
- 17
-
Actually for the struct Date and NSDate there is functionality in EVReflection that can handle it. You can see in the answer above how you can use the correct date formatter. – Edwin Vermeer Jun 22 '18 at 05:01
The default date formatter used in EVReflection is "yyyy'-'MM'-'dd' 'HH':'mm':'ssZ" If you want to change the default formatter, then you can use code like this:
dateFormatter = DateFormatter()
dateFormatter!.locale = Locale(identifier: "en_US_POSIX")
dateFormatter!.timeZone = TimeZone(secondsFromGMT: 0)
dateFormatter!.dateFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ssZ"
EVReflection.setDateFormatter(dateFormatter)
If you have one property that has a different format, then use the EVReflection propertyConverters function.

- 13,017
- 2
- 34
- 58