英文:
How to set a custom date to UUID in golang?
问题
我尝试在Golang中为UUID设置自定义日期,但无法成功设置。以下是我的代码:
package main
import (
"fmt"
"time"
guuid "github.com/google/uuid"
)
func main() {
//id := uuid.NewUUID()
t, _, _ := guuid.GetTime()
sec, nsec := t.UnixTime()
timeStamp := time.Unix(sec, nsec)
fmt.Printf("Your unique id is: %s \n", sec)
fmt.Printf("The id was generated at: %v \n", timeStamp)
}
请帮助我设置UUID的自定义日期。
英文:
I tried to set a custom date to an UUID in golang, but couldn't able to set it. This is my code:
package main
import (
"fmt"
"time"
guuid "github.com/google/uuid"
)
func main() {
//id := uuid.NewUUID()
t, _, _ := guuid.GetTime()
sec, nsec := t.UnixTime()
timeStamp := time.Unix(sec, nsec)
fmt.Printf("Your unique id is: %s \n", sec)
fmt.Printf("The id was generated at: %v \n", timeStamp)
}
Please help me in setting a custom date to UUID
答案1
得分: 1
目前google/uuid
库没有提供这样的功能。而且也不应该提供。
但是如果你真的想要实现这个功能,你需要重新实现NewUUID
函数。你可以复制源代码,并修改其中使用GetTime
的部分。
英文:
There isn't a way to do this via the google/uuid
library. And it shouldn't be.
But if you really want to do it, you need to re-implement the NewUUID
function. You could copy the code from the source and change the part where it uses the GetTime
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论