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