Suppose you are managing blog website and your user-base location are different instead of specific region. In the blog, you are displaying post creation date and times, so it is become important that you display different time according to user's location time instead of your server's time. In this article we will display time according to user timezone instead of server time. For displaying time, we will use Moment.js library. You can also use 3rd party API services, like GeoIP to get user's timezone from their IP addresses.
To use moment.js, first include bellow moment.js CDN file.
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.27/moment-timezone-with-data-2012-2022.min.js"></script>
And this is the element you want to display time in the blog post.
<div class="post"> <span id="post-time"></span> </div>
<span id="post-time"> will change server time to user's local time. You can add
format() method to change format of the time you want to display. I Hope you like this article. In upcoming article, we will discuss usage of Moment.js.
How to create a query string from an array in PHPWhen sending get request to third party...
How to check or uncheck radio button dynamically using jQueryUse the jQuery prop() method You can...
Scrolla jQuery plugin for reveal animations when scrollingIf your website contains lots of images,...
How to show and hide dropdown menu on mouse hover using CSSUse the CSS :hoverpseudo-class If you...
Laravel 8 auto logout a user after a time of inactivitySometimes we want to make automatic logg...