gpt4 book ai didi

debugging - 在 Delve 中调试时理解 `time.Time` 值

转载 作者:行者123 更新时间:2023-12-01 21:26:32 25 4
gpt4 key购买 nike

调试处理 time.Time 的程序时值,我需要能够打印这些值并理解它们。在 Delve 中,如果我打印 time.Time 类型的变量它打印对象的内部结构,并且不允许我运行 time.Time对象上的方法。

我如何理解这个结构并将其转化为我对 Unix() 将打印的内容的正常理解, UnixNano() ,或String()功能。

例如:

$ dlv test
(dlv) b calendar.go:200
(dlv) p appt
time.Time {
wall: 0,
ext: 63673770600,
loc: *time.Location {
name: "Local",
zone: []time.zone len: 4, cap: 4, [
(*time.zone)(0xc0000a8100),
],
tx: []time.zoneTrans len: 235, cap: 235, [
(*time.zoneTrans)(0xc0000bb000),
...+171 more
],
cacheStart: 1520751600,
cacheEnd: 1541311200,
cacheZone: *(*time.zone)(0xc0000a8100),},}

或者在值列表的情况下:

(dlv) p dates
[]time.Time len: 2, cap: 2, [
{
wall: 0,
ext: 63673689600,
loc: *(*time.Location)(0xc00008e9c0),},
{
wall: 0,
ext: 63673776000,
loc: *(*time.Location)(0xc00008ea80),},
]

我找到了a github ticket to add pretty-printing of time.Time values深入探究。在获得批准和发布之前,我可以做些什么来理解这些值(value)观并将其转换为更易读的形式?

作为解决方法,我考虑添加字符串类型的新变量,我将使用 .String() 的输出更新(根据需要)这些变量。或.Format(...) 。有更好的选择吗?

最佳答案

看起来像the issue添加您想要的功能已关闭。

Closing, you can instead call methods on the time value to format via the call t.Format(...) or call t.String().

关于debugging - 在 Delve 中调试时理解 `time.Time` 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52496204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com