I see that there is a Timestamp object but it doesn't seem to work. Using Python 3.6
$ pip install protobuf3
In python:
from google.protobuf.timestamp_pb2 import Timestamp
timestamp = Timestamp()
timestamp.GetCurrentTime()
Nothing is returned. What am I doing wrong?
Reference documentation and code samples for the Kubernetes Engine V1 API class Google::Protobuf::Timestamp. A Timestamp represents a point in time independent of any time zone or local calendar, encoded as a count of seconds and fractions of seconds at nanosecond resolution.
Protocol buffers (Protobuf) are a language-agnostic data serialization format developed by Google. Protobuf is great for the following reasons: Low data volume: Protobuf makes use of a binary format, which is more compact than other formats such as JSON. Persistence: Protobuf serialization is backward-compatible.
Simple example:
message Data {
google.protobuf.Timestamp tstamp = 1;
}
setting value:
message.tstamp.FromDatetime(datetime.datetime.now())
printing received message:
tstamp {
seconds: 1648070801
nanos: 661005000
}
ARRGGG I think there was a virtual env problem. It works now!
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
>>> from google.protobuf.timestamp_pb2 import Timestamp
>>> timestamp = Timestamp()
>>> timestamp.GetCurrentTime()
>>> print(timestamp)
seconds: 1521497361
nanos: 600455000
>>>timestamp
seconds: 1521497361
nanos: 600455000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With