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

544
Views
Obtenga el inicio de la fecha que pasa una zona horaria usando date-fns

Necesito usar la función startOfToday para una zona horaria específica . Por ejemplo, en mi zona horaria actual obtengo:

 // In my browser, staying at 'Europe/Madrid' timezone Intl.DateTimeFormat().resolvedOptions().timeZone // 'Europe/Madrid' (Zone +0100) startOfDay( new Date() ) // Tue Mar 01 2022 00:00:00 GMT+0100 (Central European Standard Time) /* /\ || || Obtained +0100 (Europe/Madrid) */

Obtengo el inicio de la fecha en mi zona horaria actual, ¿cómo puedo pasar una zona horaria para calcular el inicio actual del día en esa zona horaria? Estoy buscando algo como:

 // In my browser, staying at 'Europe/Madrid' timezone Intl.DateTimeFormat().resolvedOptions().timeZone // 'Europe/Madrid' (Zone +0100) startOfDay( new Date(), 'America/Toronto' ) // Tue Mar 01 2022 00:00:00 GMT-0500 (Central European Standard Time) /* /\ || || Should be -0500 (America/Toronto) */
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Logré hacerlo funcionar usando el paquete date-fns-tz :

 import { startOfDay } from "date-fns"; import { utcToZonedTime } from "date-fns-tz"; const date = new Date("2022-03-01T04:00:00.000Z") // Tue Mar 01 2022 05:00:00 GMT+0100 const timeZone = "America/Toronto" const zonedDate = utcToZonedTime(date, timeZone) // Mon Feb 28 2022 23:00:00 GMT+0100 const startOfDateInZonedTime = startOfDay(zonedDate).toISOString() // 2022-02-27T23:00:00.000Z
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!