JSFiddle - React, Tailwind, and code Playground

by 1eddy87

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div>
  <a href="http://www.codeography.com/2012/10/11/convert-timestamps-localtime-jquery.html">script here</a>
</div>
<br />
<div>
  <h5>Time in Sydney(<a href="http://www.timeanddate.com/worldclock/australia/sydney">AEST<a/> - GMT+10)</h5>
  <span>1970-06-06T22:30:00Z</span> - <span class="localtime">1970-06-06T22:30:00Z</span>
  <br />
  <span>1970-06-11T06:30:00Z</span> - <span class="localtime">1970-06-11T06:30:00Z</span>
</div>
<br />
<div>
  <h5>Time in Dublin, Ireland(<a href="www.timeanddate.com/time/zones/ist-ireland">IST</a> - GMT+1)</h5>
  <span>Need this in Dublin, Ireland local time, it's currently showing Sydney, Australia local time</span>
  <br />
  <br />
  <span>1970-06-08T07:00:00Z</span> - <span class="localtime">1970-06-08T07:00:00Z</span>
  <br />
  <span>1970-06-12T15:00:00Z</span> - <span class="localtime">1970-06-12T15:00:00Z</span>
</div>

JavaScript

(function() {
  (function($) {
    return $.fn.localtime = function() {
      var fmtDate, fmtZero;
      fmtZero = function(str) {
        return ('0' + str).slice(-2);
      };
      fmtDate = function(d) {
        var hour, meridiem;
        hour = d.getHours();
        if (hour < 12) {
          meridiem = "AM";
        } else {
          meridiem = "PM";
        }
        if (hour === 0) {
          hour = 12;
        }
        if (hour > 12) {
          hour = hour - 12;
        }
        return hour + ":" + fmtZero(d.getMinutes()) + " " + meridiem + " " + (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();
      };
      return this.each(function() {
        var tagText;
        tagText = $(this).html();
        $(this).html(fmtDate(new Date(tagText)));
        return $(this).attr("title", tagText);
      });
    };
  })(jQuery);
}).call(this);

$(document).ready(function() {
  $("span.localtime").localtime();
});