【发布时间】:2020-06-09 10:43:05
【问题描述】:
我正在尝试创建这段代码:
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 is not a type
我做错了什么?任何帮助表示赞赏!
【问题讨论】:
-
试试
time.Time而不是time.Date。 -
谢谢!这确实已经工作了:) 对我来说似乎有点困惑 time.Date 实际上是一个 time.Time 对象
-
我应该发布官方答案还是您想要?^^
-
@Tillus 总是查看您正在使用的软件包的文档。这将使您清楚地了解包提供的类型。
标签: object go variables declare