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

185
Views
Edite la fecha de creación en mangosta

Así que tengo una sección de avisos en mi sitio que muestra la fecha en que se creó el aviso. Al mostrar la fecha createdAt, se muestra así:

Jue 03 de marzo de 2022 15:11:22 GMT+0000 (hora del meridiano de Greenwich)

En cambio, me gustaría que se muestre como

03/03/2022 - 15:11

Eso es DD/MM/AÑO.

Aquí está mi esquema y mi EJS con el que lo estoy mostrando. También cómo se almacena en la base de datos.

Esquema

 const noticeSchema = new mongoose.Schema({ noticeTitle: { type: String, required: true }, noticeText: { type: String, required: true }, author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } }, {timestamps: true });

EJS

 <% notices.map(notice => notices.createdAt ) %> <%= notice.createdAt %>

Entrada de base de datos

 _id: new ObjectId("6220ead4f238fc30822e5e6d"), noticeTitle: 'test3', noticeText: '<p>test3</p>', author: { _id: new ObjectId("621e06a6c29dc2273e412537"), firstName: 'test', lastName: 'test', jobRole: 'Other', email: 'test', username: 'DeneHCAdmin', __v: 0 }, createdAt: 2022-03-03T16:20:36.680Z, updatedAt: 2022-03-03T16:20:36.680Z, __v: 0 }

¿Alguien puede ayudar?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Es tan fácil como dividir la fecha en varias constantes y conectarlas entre sí.

 const creationDate = new Date(), dateYear = creationDate.getFullYear(), dateMonth = creationDate.getMonth(), dateDay = creationDate.getDay(), dateHour = creationDate.getHours(), dateMinute = creationDate.getMinutes(); const dateFullTime = `${dateMonth}/${dateDay}/${dateYear} - ${dateHour}:${dateMinute}` console.log(dateFullTime) // expected output dd/mm/yyyy - hh:hh (if you'd want a zero before the month and day when it's only one character, you would have to make an easy if statement.)
over 4 years ago · Santiago Trujillo Report

0

const t = new Date(); const date = t.getDate(); const month = t.getMonth(); const year = t.getFullYear(); const hours = t.getHours(); const minutes = t.getMinutes(); const time = `${date}/${month}/${year} - ${hours}:${minutes}`;

Es solo una simple manipulación de fechas en javascript, no tiene nada que ver con la mangosta en sí

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!