mirror of
https://github.com/godruoyi/go-snowflake.git
synced 2025-12-23 05:25:15 +00:00
👒 fix timezone to utc and perfect example demo
This commit is contained in:
@@ -2,13 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/godruoyi/go-snowflake"
|
"github.com/godruoyi/go-snowflake"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// set starttime and machineID for the first time if you wan't to use the default value
|
||||||
|
snowflake.SetStartTime(time.Date(2021, 9, 1, 0, 0, 0, 0, time.UTC))
|
||||||
|
snowflake.SetMachineID(snowflake.PrivateIPToMachineID()) // testing, not to be used in production
|
||||||
|
|
||||||
id := snowflake.ID()
|
id := snowflake.ID()
|
||||||
fmt.Println(id)
|
fmt.Println(id) // 1537200202186752
|
||||||
|
|
||||||
sid := snowflake.ParseID(id)
|
sid := snowflake.ParseID(id)
|
||||||
// SID {
|
// SID {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ func SetStartTime(s time.Time) {
|
|||||||
panic("The start time cannot be a zero value")
|
panic("The start time cannot be a zero value")
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.After(time.Now()) {
|
if s.After(time.Now().UTC()) {
|
||||||
panic("The s cannot be greater than the current millisecond")
|
panic("The s cannot be greater than the current millisecond")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user