如何解决我们如何在swiftui中将Date对象发送到Rest Api?
目前在我的 DTO 类中,我正在声明这样的类型。
var transferDate : Date?
private enum CodingKeys: String,CodingKey {
case transferDate = "TransferDate"
}
override func encode(to encoder: Encoder) throws{
try super.encode(to:encode)
try container.encode(transferDate,forKey: .transferDate)
}
在我看来,我是这样分配日期
Dto.transferDate = self.Date
在调试时我在调试窗口看到这个
(Date) <unavailable; try printing with "vo" or "po"
任何帮助将不胜感激。 谢谢
解决方法
您不必为日期做任何自定义。我记得,默认情况下,系统将日期编码为 Double,就像 Date.timeIntervalSinceReferenceDate()
返回的那样。
如果您正在编写 RESTFUL API,您应该能够编写它来处理该日期格式。
如果您需要“互联网日期”(标准格式的日期字符串,包括与 UTC 的偏移量),您需要在设置编码器时指定。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。