0

I want to bind data in a dd-mm-yy format for which I am using json to bind. Currently I get date as 2014-06-18T00:00:00

I want in dd-mm-yy format. Kindly let me know how to do that.

Below is my code for the same.

if (getJSONValue.LAUNCH_DATE != "" || getJSONValue.LAUNCH_DATE == null) {
            $('#txtLaunchDate').val(getJSONValue.LAUNCH_DATE);
        }

my getJSONValue.LAUNCH_DATE = 2014-06-18T00:00:00

Nad
  • 4,605
  • 11
  • 71
  • 160

2 Answers2

2

see snippet

var newDate = new Date("2014-06-18T00:00:00");
var day = newDate.getDate();
var month = newDate.getUTCMonth() + 1;
var year = newDate.getFullYear();
console.log(day + "-" + ("0" + (month)) + "-" + year );
sumit chauhan
  • 1,270
  • 1
  • 13
  • 18
1

Using momentjs:

const date = '2014-06-18T00:00:00'
const format = 'DD-MM-YY'

console.log(moment(date).format(format))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment.js"></script>
Hemerson Carlin
  • 7,354
  • 1
  • 27
  • 38