Skip to content
Advertisement

convert data time to a desired format in js

I am trying to convert 2022-09-13T08:06:12.328+0000 to 13 September at 1:36 PM using javascript. In order to make things easier, I thought to install moment js and tried the conversion as below.

console.log(moment('2022-09-13T08:06:12.328+0000').calendar());

But it will print the output as Yesterday at 1:36 PM. So is there any way to change the format as I expected above(13 September at 1:36 PM) or any other best way to achieve it?

Advertisement

Answer

You could use this format :

console.log(moment('2022-09-13T08:06:12.328+0000').format('D MMMM [at] h:mm A'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement