Home > Back-end >  Can't be parsed as format error from Luxon
Can't be parsed as format error from Luxon

Time:02-05

I have a date 02/03/2022 0600 I'm trying to make a Luxon object like so

DateTime.fromFormat(`${date} ${time}`, 'MM/dd/yyy HHmm'), this results in an error the input "02/03/2022 0600" can't be parsed as format MM/dd/yyy hhmm

It works fine with dates and times separately with the same format. Is Luxon unable to parse dates and times together in this way?

CodePudding user response:

you have missed a y in 'MM/dd/yyy HHmm'. Change it to 'MM/dd/yyyy HHmm'

let a = luxon.DateTime.fromFormat('02/03/2022 0600', 'MM/dd/yyyy HHmm')
 
 console.log(a)
 
 console.log(Object.entries(a))
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.3.0/luxon.min.js"></script>

  •  Tags:  
  • Related