php中的strtotime是一个非常流行并且简单易用的函数,go中并没有内置类似的函数,不过已经有人实现了go语言的strtotime包。

github地址:https://github.com/carmo-evan/strtotime

安装

go get github.com/carmo-evan/strtotime

使用

package main

import (
	"fmt"
	"github.com/carmo-evan/strtotime"
	"time"
)

func main() {
    //Now is Nov 17, 2019
    u, err := strtotime.Parse("next Friday 3pm", time.Now().Unix())
    
    if err != nil {
        // crash and burn
    }

    t := time.Unix(u,0)
    
    fmt.Println(t)
    //output: 2019-11-22 15:00:00 +0000 UTC
}
(adsbygoogle = window.adsbygoogle || []).push({});