У меня проблемы с преобразованием времени. Время в Десекунды.Я в основном должен портировать ниже Golang
Deciseconds fits into 36 bits with enough precision to record a user's consent action timing. Javascript: Math.round((new Date()).getTime()/100)
Я пытался использовать Go / Golang Time.Now (). UnixNano () конвертировать в миллисекунды?
для преобразования в миллисекунды с последующим делением на 100. Это приводит к неправильной отметке времени.Могу поспорить, что это глупая ошибка с моей стороны, но я просто хотел получить некоторую обратную связь
Это метод, который читает метку времени, которую я пытаюсь отправить
// ReadTime reads the next 36 bits representing the epoch time in deciseconds
// and converts it to a time.Time.
func (r *ConsentReader) ReadTime() time.Time {
var ds = int64(r.ReadBits(36))
return time.Unix(ds/dsPerS, (ds%dsPerS)*nsPerDs).UTC()
}
https://github.com/LiveRamp/iabconsent/blob/328e761006ce2652bc8c0daee614381d7565c05e/parse.go#L34
Я устанавливаю дату с помощью
func (b bit) setDateToDeciseconds(startInclusive int, size int, t time.Time) {
deciseconds := int32(t.Unix() / 1000)
b.setNumberInt32(startInclusive, size, deciseconds)
}
func (b bit) setNumberInt32(startInclusive int, size int, to int32) {
for i := size - 1; i >= 0; i-- {
index := startInclusive + i
byteIndex := index / 8
shift := uint((byteIndex+1)*8 - index - 1)
b[byteIndex] |= byte((to % 2) << shift)
to /= 2
}
}
Я получаю время даты, которое выглядит как
time.Now () -> 1970-01-02 18:26:11.4 +0000 UTC