I am using Moment to work with time and what I wanted to achieve is to convert local time to UTC time. My local time is GMT+5.
So, here is my code:
moment("12:15", "HH a").utc().format("HH")
What I expect to get is 19 but I get 07. I really need your help. I am using moment.js 2.24.0.
Use hh to parse the input hours and don't forget the minutes.
console.log(moment('12:15', 'hh:mm').utc().format('HH'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Since Moment is EOL, you should use Luxon instead.
const { DateTime } = luxon;
console.log(DateTime.fromFormat('12:15', 'hh:mm').toUTC().toFormat('HH'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/2.0.2/luxon.min.js"></script>