moamoa
moamoa

Reputation: 145

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

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!

Upvotes: 5

Views: 17867

Answers (2)

molecule
molecule

Reputation: 140

With the Luxon DateTime object you can set time using set

DateTime.now().set({ hour: 0, minute: 0, second: 0, millisecond: 0 })

Upvotes: 2

moamoa
moamoa

Reputation: 145

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'));

Upvotes: 9

Related Questions