jQuery addClass example

Change class name on click in jQuery

HTML

<p id="date1">
</p>
<p id="date2">
</p>
<p id="date3">
</p>
<p id="date4">
</p>
<p id="date5">
</p>
<p id="date6">
</p>
<p id="date7">
</p>

JavaScript

setInterval(function() {
  $("#date1").text(DateToStringISO8601(new Date(), false, "", true));
}, 100)
$("#date2").text(DateToStringISO8601("2018-07-01"));
$("#date3").text(DateToStringISO8601("2018-07aw")); // Will show Today
$("#date4").text(DateToStringISO8601("2018-07-18", false));
$("#date5").text(DateToStringISO8601("2018-07-11T00:00:00Z", false, null, true));
$("#date6").text(DateToStringISO8601("2018-07-11T00:00:00Z", false, "17:53:00", true));
$("#date7").text(DateToStringISO8601("2018-07-11T00:00:00Z", false, "aa:53:00", true)); //will show date's hms

///<summary>
/// isDateOnly default : true
/// hms defualt : null (example to using "09:00:00") this parameter using when isDateOnly is false.
/// isShowUTCTimeZone default : null (example to using UTC Timezone shows like this "+09:00" ).
///</summary>
function DateToStringISO8601(date, isDateOnly, hms, isShowUTCTimeZone) {
  var datestring = "";

  if (date == null || date == "") {
    return "";
  }
  if (Object.prototype.toString.call(date) !== "[object Date]") {
    date = new Date(date);
    //if Date is NaN, set Today
    if (isNaN(date)) {
      date = new Date();
    }
  }

  datestring = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2);
  if (isDateOnly != null && isDateOnly === false) {
    if (hms == null || hms === "") {
      datestring += "T" + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2); // + "." + ("00" + date.getMilliseconds()).slice(-3);
    } else {
      var arr = hms.split(':');
      if (arr.length !== 3) {
        datestring += "T" + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2); // + "." + ("00" + date.getMilliseconds()).slice(-3);
      } else {
        if ((parseInt(arr[0]) <= 24 && parseInt(arr[0]) >= 0) && (parseInt(arr[1]) <= 60 && parseInt(arr[1]) >= 0) &&...