我正在尝试创建这段代码:
var nextWorkday time.Date
// var nextWorkday *time.Date // neither works
yyyy, mm, dd := now.Date()
goalTime, _ := time.ParseDuration(fmt.Sprintf("%fh", *goal))
goalSeconds := int(goalTime.Seconds())
if date.Weekday() != time.Friday { // wait till the next workday (7am + difference)
nextWorkday = time.Date(yyyy, mm, dd+1, 7, 0, 0+goalSeconds, 0, now.Location())
} else {
nextWorkday = time.Date(yyyy, mm, dd+3, 7, 0, 0+goalSeconds, 0, now.Location())
}
time.Sleep(nextWorkday)
重要的断点已经在第一行。我不知道如何声明自定义类型的新变量。现在我收到错误:
time.Date 不是类型
我做错了什么?任何帮助表示赞赏!
最佳答案
标准中没有time.Date
类型time
包裹。但是有一个 time.Time
表示时间瞬间的类型,“包括”日期。
time.Date()
是一个函数,它根据提供的日期和时间字段构造一个 time.Time
值。
关于object - 如何在 go 中声明自定义类型的变量(如 time.Date)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62280722/