Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format date from the object in angular

data = { name: 'Jaun', date: '2019-01-01 13:29:00', load: true }

what I want to do here is to format the date when it console the data it should be like this.

 data = { name: 'Jaun', date: '01-01-2019 01:29 PM', load: true }

1 Answers

try this.

var data = { name: 'Jaun', date: '2019-01-01 13:29:00', load: true }

function convertDate(){
 console.log(moment(data.date).format('DD-MM-YYYY hh:mm'));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<button onclick="convertDate()">Convert Date</button>
like image 89
Rohit Tagadiya Avatar answered Feb 07 '26 11:02

Rohit Tagadiya