UTC To Local Time Converter - jQuery utc2local.js

File Size: 4.02 KB
Views Total: 2429
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
UTC To Local Time Converter - jQuery utc2local.js

utc2local.js is a basic, multi-language UTC To Local Time Converter that converts Coordinated Universal Time ( UTC ) to your local date time.

How to use it:

1. Download and place the minified version of the jQuery utc2local.js script after jQuery.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" 
        integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" 
        crossorigin="anonymous">
</script>
<script src="utc2local.min.js"></script>

2. Insert your Universal Time into a container element.

<span class="datetime">
  2018-12-24 23:59:59
</span>

3. Call the plugin on the span element.

$(document).ready(() => {
  $('.datetime').utc2local();
});

4. This will convert the UTC to your local time (based on timezone):

<!-- GMT +8 -->
Tue, Dec 25, 2018 07:59

5. Localize the month and weekday strings:

let weekdayLiterals = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
let monthLiterals = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

This awesome jQuery plugin is developed by misjerrywu. For more Advanced Usages, please check the demo page or visit the official website.