Hi,
I have tried so far is $("#txtAddedDate").val(data.d.AddedDate);. But its output will be /Date(1415212200000)/. I need it in 03/06/2014 format.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Renjith V SPosted Jun 20, 2014, 2:12 AM
Your answer is correct but I found an alternative it works me well.
data.d.AddedDate is in json format.
use this function to convert date
$("#txtAddedDate").val(jsonDateformat(data.d.AddedDate));
function jsonDateformat(date) {
jsonDate = date;
var d = new Date(parseInt(jsonDate.substr(6)));
var m, day;
m = d.getMonth() + 1;
if (m < 10)
m = '0' + m
if (d.getDate() < 10)
day = '0' + d.getDate()
else
day = d.getDate();
var formattedDate = m + "/" + day + "/" + d.getFullYear();
var hours = (d.getHours() < 10) ? "0" + d.getHours() : d.getHours();
var minutes = (d.getMinutes() < 10) ? "0" + d.getMinutes() : d.getMinutes();
var formattedTime = hours + ":" + minutes + ":" + d.getSeconds();
formattedDate = formattedDate + " " + formattedTime;
return formattedDate;
}
Anupam SinghPosted Jun 19, 2014, 8:03 AM
put script this at last .And if you are getting value in txtAddedDate it will display correct format.
best of luck !
Renjith V SPosted Jun 19, 2014, 7:57 AM
Still the same problem
Anupam SinghPosted Jun 19, 2014, 7:51 AM
Actually I tried this :
it means $("#txtAddedDate").val(data.d.AddedDate) has incorrect value.so you have to correct this.
if you will try above code, will work fine.
Renjith V SPosted Jun 19, 2014, 7:47 AM
I have tried your answer but the output is
NaN/NaN/NaN
Anupam SinghPosted Jun 19, 2014, 6:11 AM
try this :
it should work.
Akhil MittalPosted Jun 19, 2014, 6:06 AM
$("#txtAddedDate").val((datecheck.Day ) + '/' + datecheck.Month + '/' + datecheck.Year))
Renjith V SPosted Jun 19, 2014, 5:45 AM
Anupam SinghPosted Jun 19, 2014, 5:33 AM
var datecheck=data.d.AddedDate;
$("#txtAddedDate").val((datecheck.getMonth() ) + '/' + datecheck.getDate() + '/' + datecheck.getFullYear()))
not tested.