Search code examples
gotimeformattingstring-formatting

How to format time.Since().String()?


What I have -> 1m16.044455998s

What I want -> 1m16s without milli-, micro-, nano- seconds.


Solution

  • Use this

    time.Since(t1).Truncate(time.Second).String()
    

    Check this go playground link for an example: https://play.golang.org/p/x7k9zuuqpRp