Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

534
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda