0

I have a Date that looks like 2019-07-22T20:58:22. This is the format I get back from our backend.

How can I convert it to Jul-22 20:58 ? I do not need any other info like years and month has to be in that three letters format.

  • put more description like what type of `database` you're using and what you've tried so far – user1318723123 Apr 02 '20 at 21:25
  • While you *can* do this by parsing to a Date then formatting, it's much simpler to just reformat the string, replacing the month number with the equivalent short name. – RobG Apr 02 '20 at 22:28

2 Answers2

0

You can try this:

import moment from 'moment';

const yourDate = '2019-07-22T20:58:22';
const formattedDate = moment(yourDate).format('MMM-DD HH:mm');

console.log(formattedDate); // "Jul-22 20:58"

Hope this help :)

-2

That is an iso 8601 format. You may use the moment library to parse your date to any format you need.

Please note this also looks like a duplicate to the following. see link for an excellent overview of your issue

duplicate question

monkeyjumps
  • 682
  • 1
  • 12
  • 23
  • If the question is a duplicate, you should vote to close it as a duplicate, not post a comment as an answer with a link to the duplicate. – RobG Apr 02 '20 at 22:26