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

248
Views
El uso de datetime.now da el error datetime.datetime

así que he estado en el lenguaje python haciendo cosas. Me encuentro con un error que no es tan comprensible:

 TypeError: 'datetime.datetime' object is not subscriptable

(Creo) este es el código que lo causa:

 def brew(): # Get UTC time curr_dt = datetime.now(timezone.utc) # Slice it curr_dt = curr_dt[0:19] # Print print(curr_dt)

¿Qué estoy haciendo mal? Solo quiero obtener la fecha y la hora en 2022-01-04 14:25:10.860837+00:00 cortándola. ¿Existe una solución de cómo deshacerse del error o incluso viene con formas más fáciles y/o prácticas? Gracias por tu tiempo.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Usa el siguiente código:

 from datetime import datetime, timezone def brew(): # curr_dt = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S') curr_dt = str(datetime.now(timezone.utc))[:19] print(curr_dt)

Producción:

 >>> brew() '2022-01-04 14:35:04'
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!