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

108
Views
Cómo cambiar el formato de la fecha actual al almacenarla en la base de datos mongoDB

En el esquema de mongoDB, intento almacenar la fecha actual usando date.now(), pero está almacenando la fecha en formato UTC. ¿Cómo puedo cambiar el formato de fecha en la fecha local?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

MongoDB almacena fechas en BSON Tipo de fecha , marca de tiempo UTC con entero de 64 bits internamente. Lo que desea es almacenar las fechas como formato de fecha local, solo guárdelas con el formato String , no Date . Lo que desea es ver los valores de fecha como hora local, considere usar la expresión de agregación $dateToString .

Por ejemplo:

 db.getCollection('users').aggregate([ { $project: { createdAt: { $dateToString: { date: '$createdAt', timezone: 'Asia/Seoul' } } } } ]) // { "_id": ..., "createdAt" : ISODate("2020-12-02T04:52:02.237Z") } // -> { "_id": ..., "createdAt": "2020-12-02T13:52:02.237Z" }
about 4 years ago · Juan Pablo Isaza 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!