我正在編寫一個(gè)抓取網(wǎng)站報(bào)價(jià)的抓取工具,這些報(bào)價(jià)有結(jié)束日期。一個(gè)這樣的網(wǎng)站提供每周日到期的優(yōu)惠。我已經(jīng)閱讀了 golang 時(shí)間文檔,但仍然不明白如何完成我在 PHP 中發(fā)現(xiàn)的等效性并且非常簡(jiǎn)單。$endDate = strtotime('this Sunday, 23:59:59');有沒有 golang 的方法來做到這一點(diǎn)?
1 回答

慕妹3146593
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊
使用Go 標(biāo)準(zhǔn)庫時(shí)間包在 Go 中編寫一個(gè)函數(shù)。例如,
package main
import (
? ? "fmt"
? ? "time"
)
func endDate(t time.Time, wd time.Weekday) time.Time {
? ? next := int((wd - t.Weekday() + 7) % 7)
? ? y, m, d := t.Date()
? ? return time.Date(y, m, d+next+1, 0, 0, 0, -1, t.Location())
}
func main() {
? ? now := time.Now().Round(0)
? ? fmt.Println(now, now.Weekday())
? ? end := endDate(now, time.Sunday)
? ? fmt.Println(end, end.Weekday())
}
輸出:
2018-11-08?05:25:01.104445722?-0500?EST?Thursday 2018-11-11?23:59:59.999999999?-0500?EST?Sunday
- 1 回答
- 0 關(guān)注
- 180 瀏覽
添加回答
舉報(bào)
0/150
提交
取消