How to do date/time comparison

后端 未结 5 1868
一向
一向 2020-12-23 15:25

Is there any options in doing date comparison in Go? I have to sort data based on date and time - independently. So I might allow an object that occurs within a range of dat

5条回答
  •  囚心锁ツ
    2020-12-23 16:07

    The following solved my problem of converting string into date

    package main

    import (
        "fmt"
        "time"
    )
    
    func main() {
        value  := "Thu, 05/19/11, 10:47PM"
        // Writing down the way the standard time would look like formatted our way
        layout := "Mon, 01/02/06, 03:04PM"
        t, _ := time.Parse(layout, value)
        fmt.Println(t)
    }
    
    // => "Thu May 19 22:47:00 +0000 2011"
    

    Thanks to paul adam smith

提交回复
热议问题