This library will help you transform data time to user time according to user timezone
- Your data need to have time and timezone
- Jquery
- Moment
- Moment time zone
- jstz
- Assign class to elements
- Call userTimezone(format); on class selector
PS. See demo.html for example. Don't forget to run bower install
to download all dependencies before run the demo.
Code example:
<ul>
<li data-timezone="Europe/London" data-time="2016-08-14 22:00:00" class="time"></li>
<li data-timezone="Europe/London" data-time="2016-08-15 18:30:00" class="time"></li>
<li data-timezone="Europe/London" data-time="2016-08-16 20:00:00" class="time"></li>
<li data-timezone="Europe/London" data-time="2016-08-16 23:45:00" class="time"></li>
<li data-timezone="Europe/London" data-time="2016-08-17 08:30:00" class="time"></li>
<li data-timezone="Europe/London" data-time="2016-08-18 10:00:00" class="time"></li>
</ul>
Call userTimezone method on class selector
<!-- Include user-tz.js -->
<script src="user-tz.js"></script>
<script>
$(function() {
// Initialize userTimezone for all element with class time
$(".time").userTimezone("YYYY-MM-DD HH:mm");
});
</script>
Result (depend on your timezone)
2016-08-15 04:00
2016-08-16 00:30
2016-08-17 02:00
2016-08-17 05:45
2016-08-17 14:30
2016-08-18 16:00
This library will use browser timezone.