dongmiao260399 2019-08-27 15:01
浏览 43

打印时间时出现意外输出。时间[重复]

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>
  • 写回答

1条回答 默认 最新

  • dtp791357 2019-08-27 15:03
    关注

    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).

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码