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

143
Views
Convierta la cadena en fecha y luego en marca de tiempo para agregar a firestore

De acuerdo, tengo dos componentes nativos de reacción DateTimePicker que uso para recopilar una fecha y hora del usuario usando la siguiente función de cambio

 const onChangeDate = (event, selectedDate) => { const currentDate = selectedDate || date; setDateShow(Platform.OS === 'ios'); setDate(currentDate); let tempDate = new Date(currentDate); let date = tempDate.getFullYear() + '-' + tempDate.getMonth() + '-' + tempDate.getDate(); console.log(date); //2022-4-18 setFinalDate(date); } const onChangeTime = (event, selectedTime) => { const currentTime = selectedTime || time; setTimeShow(Platform.OS === 'ios'); setTime(currentTime); let tempDate = new Date(currentTime); let time = tempDate.getHours() + ':' + tempDate.getMinutes() + ':' + tempDate.getSeconds() + tempDate.getMilliseconds(); console.log(time); //0:10:00 setFinalTime(time); }

Después de establecer un estado para finalTime y finalDate

 const eventTimestamp = (`${finalDate} ${finalTime}`); console.log(eventTimestamp) // output is 2022-4-18 0:10:00

Parece que no puedo convertir esto en un objeto de fecha () y luego en una marca de tiempo usando el método toMillis () porque quiero agregar esto en firestore como una marca de tiempo. Convertirlo en una fecha usando new Date() me da Fecha { NaN } y usando el método firestore firebase.firestore.Timestamp.fromDate(works) me da Objeto { "nanosegundos": NaN, "segundos": NaN, }

¿Tuviste suerte con dónde me equivoqué?

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

0

Debe analizar la cadena de fecha y luego convertirla en un objeto date() . Vea el código de muestra a continuación:

 // Initiate a new Date object. const eventTimestamp = new Date( // Parse the string into a date Date.parse( `${finalDate} ${finalTime}` ) ) await setDoc(doc(db, "<collection>", "<document-id>"), { timestamp: eventTimestamp });

Para obtener más información, puede consultar esta documentación .

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!