I work with two js libraries to get browser timezone id and local browser time
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js"></script> <script src="Scripts/moment-timezone.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { var tz = jstz.determine(); </script>
this code below returns the perfect timezone id
var tz = jstz.determine();
but this code does not work alert(moment.tz(tz.name()).format()); does not give the user local time.
Am I missing something in the code? Do I need to add any file related to other events?
please guide me. I want to get the user's local time using moment.js. thanks
Working version of UPDATE
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript" src="Scripts/jstz.min.js"></script> <script src="Scripts/moment.min.js" type="text/javascript"></script> <script src="Scripts/moment-timezone-with-data-2010-2020.min.js" type="text/javascript"></script> </head> <body> <form method="post" action="WebForm1.aspx" id="form1"> <div> <script type="text/javascript"> $(document).ready(function () { var tz = jstz.determine(); </script> </div> </form> </body> </html>
source share