JSFiddle - React, Tailwind, and code Playground
by priyanka tiwari
HTML
<span id="today">hjkhjkh</span>
<br/>
<span id="datetime">hjkhjkh</span>
JavaScript
Date.prototype.yyyymmdd = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString();
var dd = this.getDate().toString();
//var hh = this.getDate().toString();
// var ii = this.getDate().toString();
return yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]);
};
d = new Date();
$('#today').html(d.yyyymmdd());
var currentdate = new Date();
// For todays date;
Date.prototype.today = function () {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"-"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"-"+ this.getFullYear();
}
// For the time now
Date.prototype.timeNow = function () {
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes();
}
var datetime = new Date().today() + " " + new Date().timeNow();
$('#datetime').html(datetime);