Error Time converting

Hey there, I’m trying the following code but it’s not working, it only gives me “0001-01-01 00:00:00.000”. What am I doing wrong?

package main

import (
	"fmt"
	"time"
)

func main() {
		DataHoraGPS, _ := time.Parse("2006-01-02 15:04:05", "02/07/2016¨18:20:11")

	testestringdata := DataHoraGPS.Format("2006-01-02 15:04:05") + ".000"
	fmt.Println(testestringdata)
}

Tnx.

The first issue is that you are ignoring the error returned from time.Parse that tells you what the problem is. The second issue is that the time format doesn’t match what you’re trying to parse. (I don’t know if the dieresis after the year was intentional, but it can be parsed so I left it in there.)

package main

import (
	"fmt"
	"log"
	"time"
)

func main() {
	DataHoraGPS, err := time.Parse("01/02/2006¨15:04:05", "02/07/2016¨18:20:11")
	if err != nil {
		log.Fatal(err)
	}
	testestringdata := DataHoraGPS.Format("2006-01-02 15:04:05") + ".000"
	fmt.Println(testestringdata)
}

(The “Share” button on play.golang.org does nothing for me at the moment. I don’t know if I’m the only one.)

3 Likes

Hey friend thanks for your reply, and not, that wasn’t intentional, I’ve only seen that when you showed me, that’s too small and my monitor is full of dust, I cutted it but nothing has changed. Any idea of what should it be?

PS: About Share button on playgroung, I noticed that too, that’s not working to me also…

Tnx.

Should be? I think a space is probably expected. I’m not sure what you mean by nothing changed, the code I pasted above works fine.

1 Like

No it’s not working…

2 Likes

That works! Thanks a lot man… Thank you so much…

just for info, the Share button is working now : https://play.golang.org/p/Ubds1LUkpj

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.