Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 如何比较两个时间戳-只是因为其中一个有时区而不同?_Date_Datetime_Go_Testify - Fatal编程技术网

Date 如何比较两个时间戳-只是因为其中一个有时区而不同?

Date 如何比较两个时间戳-只是因为其中一个有时区而不同?,date,datetime,go,testify,Date,Datetime,Go,Testify,我试图测试插入postgres数据库的time.time值是否与我查询的值相同。然而,Postgres放弃了时区,所以我想知道如何才能通过这个验证/断言测试 s.Equal(want.Date,got.Date) 两者都是dame数据类型time.time,但第一个具有时区: 2020-10-31 00:00:00+0000 UTC 我像这样创建了这个值-time.Date()必须有一个位置,因此我无法通过传递nil来创建没有位置的值: want.Date:=time.Date(2020,10,

我试图测试插入postgres数据库的
time.time
值是否与我查询的值相同。然而,Postgres放弃了时区,所以我想知道如何才能通过这个验证/断言测试

s.Equal(want.Date,got.Date)

两者都是dame数据类型
time.time
,但第一个具有时区:

2020-10-31 00:00:00+0000 UTC

我像这样创建了这个值-
time.Date()
必须有一个位置,因此我无法通过传递nil来创建没有位置的值:

want.Date:=time.Date(2020,10,31,00,00,00,0000,time.UTC)

来自数据库的
get.Date
如下所示:

2020-10-31 00:00:00+0000+0000


我无法更改删除时区的数据库,因此如何更改创建日期的方式或如何删除时区?或者,也许有另一种方法可以断言年、月和日是相同的?

使用
time.time.Equal
测试
time.time
类型的两个值是否相等

$ go doc time.Time.Equal
package time // import "time"

func (t Time) Equal(u Time) bool
    Equal reports whether t and u represent the same time instant. Two times can
    be equal even if they are in different locations. For example, 6:00 +0200
    and 4:00 UTC are Equal. See the documentation on the Time type for the
    pitfalls of using == with Time values; most code should use Equal instead.


啊,我在尝试从一个时区中删除时区的方法,但我找不到如何做并保持它的时间。时间价值仍然存在。谢谢