gpt4 book ai didi

swift - Swift 期望如何写日期?

转载 作者:搜寻专家 更新时间:2023-11-01 05:34:11 25 4
gpt4 key购买 nike

<分区>

import Foundation 之后,我写了一个名为“Employee”的类。它的属性之一是 Date 类型。我的问题是:在实例化 Employee 时,如何设置其 Date 属性值的格式?(我试过 YYYY-MM-DD、MM-DD-YYYY 和其他一些,但 Xcode 不会接受。)

这是类:

class Employee {
let name: String
let address: String
let startDate: Date
let type: EmployeeType

init(name: String, address: String, startDate: Date, type: EmployeeType) {
self.name = name
self.address = address
self.startDate = startDate
self.type = type
}

这是创建实例的尝试(不接受 2017-10-19):

let nick = Employee(name: "Nick", address: "61", startDate: 2017-10-19, type: EmployeeType.traditional)

非常感谢,
尼克

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com