Thanks all for the hint and the snippets. I am all set now.

On Tuesday, 5 April 2022 at 00:13:46 UTC+10 tay...@fastmail.com wrote:

> Take a look at time.ParseDuration and its example: 
> https://pkg.go.dev/time#ParseDuration
>
> On Sun, Apr 3, 2022, at 3:48 PM, vika...@gmail.com wrote:
>
> I am looking to convert a *string* (say 4) to type *time.Duration*.
>
> I've looked around but could not find a way to do so.
>
> // https://go.dev/play/p/EUuDAY-Qx8N
> package main
>
> import (
>     "fmt"
>     "time"
> )
>
> func main() {
>     // var addHours string = 4
>     fmt.Println(time.Now().Local())
>     timeAdd := time.Now().Local().Add(time.Hour * 4) // I want to use 4 
> from a string variable here
>     fmt.Println(timeAdd)
> }
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/72d548fc-f572-4ff5-9516-3e13fa04850dn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/72d548fc-f572-4ff5-9516-3e13fa04850dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/159a25e2-7912-46e3-8c41-116ca887cec0n%40googlegroups.com.

Reply via email to