I'm a web dev beginner and got a problem with a timestamp and need your help!
I'm working on a posting formula and a posting displayer. In the formula, I save the posting timestamp in "seconds" into the database.
If the user clicks on a button, more information will show up, also the "creation date".
The user do have the choice via a date configuration how the date will get displayed, for example month/day/year or day.month.year, ...
That is the reason why I save the timestamp in seconds to the database and not directly in a date like: month/day/year
$tm = time();
So my ajax formula must fetch the timestamp in seconds from the database and transform it to a date on the fly.
I found in this forum a solution how to transform seconds to a date via javascript but I don't know how to implement it to ajax.
With my code I dont have problems to fetch information from database, it works perfectly fine, but I only know how to fetch the date in seconds, like: 1538395461
Here is a shorter version of my code
AJAX CODE
<script>
var buttons = document.querySelectorAll("a.img_title");
for(var x=0; x < buttons.length; x++)
{
buttons[x].addEventListener('click', loadDescr);
}
function loadDescr(e)
{
var abc = e.target.getAttribute('data-xy');
var xhr_ap = new XMLHttpRequest();
xhr_ap.open('GET', 'includes/ajax/ajax_posts_conn.php?ref_desr=' + abc, true);
xhr_ap.onload = function()
{
if (this.status == 200)
{
/*----------------------------------------------------------------------*/
var post_header = JSON.parse(this.responseText);
/*----------------------------------------------------------------------*/
var output = '';
for (var i in post_header)
{
output += '<ul>' +
'<li><a>created: '+post_header[i].post_created+'</a></li>' +
'</ul>';
}
document.getElementById('post_creation_date').innerHTML = output;
/*----------------------------------------------------------------------*/
}
}
xhr_ap.send();
}
</script>
"post_created" is the name of the table row.
"post_creation_date" is the name of the div in my html, where the information get sent to.