Skip to content

Instantly share code, notes, and snippets.

@edr3x
edr3x / uuidv7_timestamp_extrator.md
Created April 19, 2024 08:19
Extract timestamp from UUIDv7 string

Code

func extractTimestamp(uuid string) (time.Time, error) {
	parts := strings.Split(uuid, "-")
	millisecondsStr := parts[0] + parts[1]
	milliseconds, err := strconv.ParseInt(millisecondsStr, 16, 64)
	if err != nil {
		return time.Time{}, err
	}