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

175
Vistas
Trying pass datetime to the api

I am trying to pass the current client local date time to API by using the GET method, getting the error,

UI:

  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)
    {  

        .....
        ....
     }

I am getting the below error.

{"errors":[{"message":"Either the parameter query or the parameter id has to be set.","extensions":{"code":"HC0013"}}]}

I cannot use the server time, and I need to use only the client date and time for processing the results. I am looking into this type of string "12-19-2012, 7:00:00 PM"

Could anyone please let me know, Where I am doing wrong with the above code?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

new Date().toISOString() will produce ISO format which the API's generally accept( ISO-8601).

Console.log(new Date().toISOString()) 

Result:'2022-07-25T22:20:38.413Z'
about 4 years ago · Santiago Trujillo Denunciar

0

this line of code const localDateTime = new Date().toLocaleString(); is producing

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

wich is not valid in URL.

try changing it to a valid form maybe like this :

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 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