i want to show datetime in the format March 03, 2017 T 07:30:00
this is my script
<script>
$(document).ready(function () {
var from = "";
$('#loadings').show();
$.ajax({
type: "GET",
url: 'http://apis.fdf.df/api/Get_Loadsheet_Details/<?php
echo $number; ?>',
dataType: 'json',
success: function (response) {
$('#loadings').hide();
console.log(response);
document.getElementById('ldate').innerHTML =
response[0].DATE;
}, error: function (errors) {
console.log(errors);//alert('hi');
$('#loadings').hide();
$('#error').html("<h2><span style='color:red;'>No data
found on this LR No.</span></h2>");
}
});
});
</script>
my api's console output is
[{"DATE":"2017-04-03T00:00:00","lrConfirmStatus":null,"lrLoadStatus":null}]
i want to bind it to the field with id "ldate"
<tr>
<td>LOAD DATE:</td>
<td id="ldate"> </td>
</tr>
You need to add the following to your success
$("#ldate").append(response[0]["DATE"])
You need a function that format your date. formatDate function format date by you want:
<script>
$(document).ready(function () {
var from = "";
$('#loadings').show();
$.ajax({
type: "GET",
url: 'http://apis.fdf.df/api/Get_Loadsheet_Details/<?php
echo $number; ?>',
dataType: 'json',
success: function (response) {
$('#loadings').hide();
console.log(response);
document.getElementById('ldate').innerHTML = formatDate(response[0].DATE);
},
error: function (errors) {
console.log(errors);//alert('hi');
$('#loadings').hide();
$('#error').html("<h2><span style='color:red;'>No data found on this LR No.</span></h2>");
}
});
});
function formatDate(date_string) {
var date = new Date(date_string);
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
if(day < 10) {
day = '0'+day;
}
return monthNames[monthIndex] + ' ' + day + ', ' + year + ' T ' + date.getHours()+':' + date.getMinutes() +':' +date.getSeconds();
}
</script>