My SQL database stores datetimes, but when I try to display them on a cshtml page, it shows this format:
date:/Date(1432549851367)/
However, in the actual database, the datetime is presented as:
2015-05-25 14:30:51.367
Why is there a difference?
This is the code I have:
var conv = (from c in db.Conversations
where (c.FirstUser == user.Id && c.AdminUser == id)
|| (c.FirstUser == id && c.AdminUser == user.Id)
select new
{
Message = from m in c.Messages
select new MessageData()
{
Message = m.Message1,
SentTime = m.MessageTime,
From = m.User.UserName
}
}).FirstOrDefault();
This is my model class:
public class MessageData
{
public string From { get; set; }
public string Message { get; set; }
public DateTime? SentTime { get; set; }
}
And here's how I render it on the page:
function refresh(id) {
$.getJSON("../Chat/ViewConversation/" + id, function (data) {
$('#ToId').val(id);
$('#conversations').html('');
if (data[0].Message1 == 'no message') {
$('#conversations').append('no message');
} else {
for (var i = 0; i < data.length; i++) {
console.log(data[i].SentTime);
var ctx = '<div class="from">' + data[i].From + '</div>' +
'<div class="messageBody">' + data[i].Message + '</div>' +
'<div class="date">date:' + data[i].SentTime + '</div><hr/>';
$('#conversations').append(ctx);
}
}
});
The message and username are displayed correctly, but the datetime is not. How can I fix this issue?