Setting a time in Luxon and showing it in the user's local timezone
Asked Answered
W

2

5

I'm using Luxon to show when orders will be processed. If they place an order after business hours 9am-5pm EST, I want to tell them their order will be ready at 2:00pm EST the following day.

    let easternTime = luxon.DateTime.local().setZone('America/New_York');
    let localTime = luxon.DateTime.local();
    // Omitted/Irrelevant Logic to determine if time is after 9am-5pm EST

    console.log("Business closed...turnaround next day");
    console.log(easternTime.toLocal().plus({ day: 1 }).toFormat('EEE, MMM d, 2:00 a ZZZZ'));

If someone see's this message in San Francisco (PST), I'd like the time to read 11:00am PST. How would I go about accomplishing this with Luxon or some other framework?

Thank you!

Weisler answered 26/10, 2020 at 21:43 Comment(0)
W
9

Just needed to use the .set({ hour: 14 }) functionality:

console.log(easternTime.set({ hour: 14 }).set({ minutes: 0 }).toLocal().plus({ day: 1 }).toFormat('EEE, MMM d, h:mm a ZZZZ'));
Weisler answered 26/10, 2020 at 22:31 Comment(0)
U
2

With the Luxon DateTime object you can set time using set

DateTime.now().set({ hour: 0, minute: 0, second: 0, millisecond: 0 })
Unbridled answered 19/1, 2023 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.