JSFiddle - React, Tailwind, and code Playground
by Anupama
HTML
<br /><br />
<p id="localDate"></p>
<input type="text" id="date"/>
<input type="text" id="hours" size="3"/>
<input type="text" id="minutes" size="3"/>
<span id="amPm"> </span>
JavaScript
function epochToJsDate(ts){
// ts = epoch timestamp
// returns date obj
return new Date(ts*1000);
}
function jsDateToEpoch(d){
// d = javascript date obj
// returns epoch timestamp
return (d.getTime()-d.getMilliseconds())/1000;
}
var epoch=1349618225;
var toDate=epochToJsDate(epoch);
//console.log("toDate : " + toDate);
var year=toDate.getUTCFullYear();
var month = toDate.getUTCMonth() + 1;
var day = toDate.getUTCDate();
var hrs=toDate.getUTCHours();
var mins = toDate.getUTCMinutes();
var date=day + "/" + month + "/" + year;
$("#localDate").html(toDate);
$("#date").attr("placeholder",date);
$("#hours").attr("placeholder",hrs);
$("#minutes").attr("placeholder",mins);