Answer my own question here, it was a silly mistake from me, the error was about the container not the encoder, correct code looks as follows
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .custom({ date, encoder in
var container = encoder.singleValueContainer()
try container.encode(date.timeIntervalSince1970)
})
It's been a long year!!!!