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

174
Views
Intentando pasar fecha y hora a la API

Estoy tratando de pasar la fecha y hora local del cliente actual a la API usando el método GET, obteniendo el error,

interfaz de usuario:

 const localDateTime = new Date().toLocaleString(); await fetchDocument(`${process.env.REACT_APP_API_URL}/api/projects/${projectNumber}/${localDateTime}/${currentProjectPhase}`, setIsBodDownloading, instance, history );

API:

 [HttpGet("{projectNumber}/{localDateTime}/{projectPhase?}")] public async Task<ActionResult> BasisOfDesign( [FromServices] IDbContextFactory<APIDbContext> serviceScopeFactory, [FromServices] ICrmProjects crmProjects, [FromServices] IConfiguration configuration, [FromServices] IEmployeeContext employeeContext, string projectNumber, string localDateTime, string projectPhase = null, CancellationToken cancellationToken = default) { ..... .... }

Recibo el siguiente error.

{"errors":[{"message":"Se debe configurar la consulta del parámetro o la identificación del parámetro".","extensions":{"code":"HC0013"}}]}

No puedo usar la hora del servidor y solo necesito usar la fecha y la hora del cliente para procesar los resultados. Estoy investigando este tipo de cadena "19-12-2012, 7:00:00 p. m."

¿Podría alguien decirme dónde estoy haciendo mal con el código anterior?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

new Date().toISOString() producirá el formato ISO que generalmente aceptan las API (ISO-8601).

 Console.log(new Date().toISOString()) Result:'2022-07-25T22:20:38.413Z'
about 4 years ago · Santiago Trujillo Report

0

esta línea de código const localDateTime = new Date().toLocaleString(); está produciendo

 7/25/2022, 9:59:46 PM

que no es válido en la URL.

intente cambiarlo a una forma válida, tal vez así:

 var dateObj = new Date(); var month = dateObj.getUTCMonth() + 1; //months from 1-12 var day = dateObj.getUTCDate(); var year = dateObj.getUTCFullYear(); newdate = year + "/" + month + "/" + day; console.log(newdate) // producing valid form to be used in URL like this 2022/7/25
about 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!