Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

533
Views
How do i create a protobuf3 Timestamp in python?

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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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
over 4 years ago · Santiago Trujillo Report

0

The only two args of constructing a protobuf Timestamp are seconds and nanos. They are defined as the seconds from the Epoch (1970-01-01 00:00:00). So we can do:

import datetime
from google.protobuf.timestamp_pb2 import Timestamp

t = datetime.datetime.now().timestamp()
seconds = int(t)
nanos = int(t % 1 * 1e9)

proto_timestamp = Timestamp(seconds=seconds, nanos=nanos)
over 4 years ago · Santiago Trujillo Report

0

timestamp.GetCurrentTime()

Actually this method fills in the current time rather than getting the current time.

Check documentation here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!