func TimestampProto(t time.Time) (*Timestamp, error) {
	seconds := t.Unix()
	nanos := int32(t.Sub(time.Unix(seconds, 0)))
	ts := &Timestamp{
		Seconds: seconds,
		Nanos:   nanos,
	}
	if err := validateTimestamp(ts); err != nil {
		return nil, err
	}
	return ts, nil
}
TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
It returns an error if the resulting Timestamp is invalid.
package types
import (
	"errors"
	"fmt"
	"time"
)
const (
	minValidSeconds = -62135596800
	maxValidSeconds = 253402300800
)
func validateTimestamp(ts *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
}
func TimestampFromProto(ts *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() *Timestamp {
	ts, err := TimestampProto(time.Now())
	if err != nil {
		panic("ptypes: time.Now() out of Timestamp range")
	}
	return ts
}