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

79
Views
Format time only with Luxon

I have a time saved as a string in my database. I'm trying to parse that time using Luxon, and then set various date parts to my various controls. While I'm not getting any errors during the parsing, I'm getting unexpected values.

The time I'm testing with: 12:05 AM America/Chicago

I'm attempting to parse as follows.

const date = DateTime.fromFormat(value, 'hh:mm a z');

The output is

Hour: 1 (incorrect)

Minute: 05 (correct)

Meridien: (AM) (correct)

Timezone: America/New_York (incorrect)

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

0

If you set opts.setZone to true, it will keep the DateTime in Chicago time, so any output will be displayed in that timezone.

To display the time in your local zone you can use DateTime.toLocal().

You can switch zone again by using the DateTime.setZone() function if you need to.

const { DateTime } = luxon;

const value = '12:05 AM America/Chicago';

const date = DateTime.fromFormat(value, 'hh:mm a z', { setZone: true });

console.log('Timezone:', date.toFormat('z'))
console.log('Time (Chicago):', date.toFormat('hh:mm a'))
console.log('Time (local):', date.toLocal().toFormat('hh:mm a'))
console.log('Time (New York):', date.setZone('America/New_York').toFormat('hh:mm a'))
.as-console-wrapper { max-height: 100% !important; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.3.1/luxon.min.js" integrity="sha512-Nw0Abk+Ywwk5FzYTxtB70/xJRiCI0S2ORbXI3VBlFpKJ44LM6cW2WxIIolyKEOxOuMI90GIfXdlZRJepu7cczA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

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!