This question already has an answer here:
"I'm trying to output the values of a channel , which received values from a struct, which should be a string and time. It outputs those two, but then it includes this strange line " +0300 +03 m=+0.001997101" after the time."
Tried many other things from fmt package, but still no help. Tried things from the time package too
package main
import (
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
var wg sync.WaitGroup
type widget struct {
Label string
Time time.Time
}
func main() {
c := make(chan widget)
sc := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sc, syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGHUP,
syscall.SIGKILL,
syscall.SIGSEGV,
)
go func() {
sig := <-sc
fmt.Println()
fmt.Println(sig)
done <- true
}()
go send(c)
go receive(c)
<-done
fmt.Println("Program exited")
}
func send(p chan<- widget) {
producer := widget{
"widget_id_34",
time.Now(),
}
p <- producer
}
//where im grtting the problem from i beilieve
func receive(c <-chan widget) {
out := <-c
fmt.Printf("%v", out)
//fmt.Fprintln(os.Stdout, <-c)
}
</div>
The m
field is the monotonic time. Per the docs:
The canonical way to strip a monotonic clock reading is to use
t = t.Round(0)
.
Doing so yields a time without a m
value. The +0300
is the time zone offset, which is part of the time value (without it, the time value would be useless, because it would have a margin of error of +/- 23 hours).