I
I
impressive172020-06-20 21:28:18
go
impressive17, 2020-06-20 21:28:18

How to convert string to date in GOLANG?

Let's say I have a string dt:="2020-06-25". How can I convert it to a date type so that I can then, for example, do this:
dt1 := dt.Add(1 *time.Hour)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Maslov, 2020-06-20
@impressive17

dt:="2020-06-25"
dt1, err := time.Parse("2006-01-02", dt)

https://play.golang.org/p/syjj52Q6QQz

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question