Golang: How to Convert time.Time to a Protobuf Timestamp?

Viewed 4418

I have a time.Time variable in Golang 10-30 00:49:07.1236 that needs to be converted to a Go Protobuf timestamp.Timestamp. Any idea on what functions can be used to accomplish this? Or am I looking at this from the wrong angle?

2 Answers

Below code will give current time in timestamppb format

import "google.golang.org/protobuf/types/known/timestamppb"
timeNow := timestamppb.Now()

Below will return time in time.Time format

timeNow.GetCurrentTime().AsTime()
Related