func validateTimestamp(ts *timestamppb.Timestamp) error {
	if ts == nil {
		return errors.New("timestamp: nil Timestamp")
	}
	if ts.Seconds < minValidSeconds {
		return fmt.Errorf("timestamp: %v before 0001-01-01", ts)
	}
	if ts.Seconds >= maxValidSeconds {
		return fmt.Errorf("timestamp: %v after 10000-01-01", ts)
	}
	if ts.Nanos < 0 || ts.Nanos >= 1e9 {
		return fmt.Errorf("timestamp: %v: nanos not in range [0, 1e9)", ts)
	}
	return nil
}
validateTimestamp determines whether a Timestamp is valid.
A valid timestamp represents a time in the range [0001-01-01, 10000-01-01)
and has a Nanos field in the range [0, 1e9).

If the Timestamp is valid, validateTimestamp returns nil.
Otherwise, it returns an error that describes the problem.

Every valid Timestamp can be represented by a time.Time,
but the converse is not true.
package ptypes
import (
	"errors"
	"fmt"
	"time"
	timestamppb "github.com/golang/protobuf/ptypes/timestamp"
)
const (
	minValidSeconds = -62135596800
	maxValidSeconds = 253402300800
)
func Timestamp(ts *timestamppb.Timestamp) (time.Time, error) {
	var t time.Time
	if ts == nil {
		t = time.Unix(0, 0).UTC()  
	} else {
		t = time.Unix(ts.Seconds, int64(ts.Nanos)).UTC()
	}
	return t, validateTimestamp(ts)
}
func TimestampNow() *timestamppb.Timestamp {
	ts, err := TimestampProto(time.Now())
	if err != nil {
		panic("ptypes: time.Now() out of Timestamp range")
	}
	return ts
}
func TimestampProto(t time.Time) (*timestamppb.Timestamp, error) {
	ts := &timestamppb.Timestamp{
		Seconds: t.Unix(),
		Nanos:   int32(t.Nanosecond()),
	}
	if err := validateTimestamp(ts); err != nil {
		return nil, err
	}
	return ts, nil
}
func TimestampString(ts *timestamppb.Timestamp) string {
	t, err := Timestamp(ts)
	if err != nil {
		return fmt.Sprintf("(%v)", err)
	}
	return t.Format(time.RFC3339Nano)
}