0

I want to parse a datetime string like YYYY-MM-DD HH:mm:ss.

However I am having extreme difficulty doing this even after reading the doc.

package main

import (
    "fmt"
    "time"
)

func main() {
    timestamp, err := time.Parse("2006-12-25 11:00:00", "2018-06-13 05:10:59")

    if err != nil {
        panic(err)
    }

    fmt.Println(timestamp.String())
}

Returns:

panic: parsing time "2018-06-13 05:10:59" as "2006-12-25 11:00:00": cannot parse "-13 05:10:59" as "2"

What am I missing?

Thanks

PedroD
  • 5,670
  • 12
  • 46
  • 84
  • 1
    The layout string must be always the same, fixed timestamp, the reference time, in the format you want to process. So you have to use the following layout string: `"2006-01-02 15:04:05"` – icza Jun 14 '18 at 11:23
  • Ah I get it. Reading through the docs that wasn't very clear to me. It needs to be that exact timestamp...! Thanks – PedroD Jun 14 '18 at 11:31

0 Answers0