Skip to content

Instantly share code, notes, and snippets.

@sivasankars
Created December 24, 2016 03:59
Show Gist options
  • Save sivasankars/7b2214b5e2992fc75f2218ed9b97c32f to your computer and use it in GitHub Desktop.
Save sivasankars/7b2214b5e2992fc75f2218ed9b97c32f to your computer and use it in GitHub Desktop.
Dynamic Time Zones Dropdown Using Moment.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dynamic Time Zones Dropdown Using Moment.js</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/css/bootstrap-select.min.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="starter-template">
<h1>Dynamic Time Zones Dropdown Using Moment.js</h1>
<p class="lead" style="width: 50%;">Dropdown contains a list of time zones, Which gets a data dynamically from Moment.js</p>
<select class="selectpicker" data-live-search="true"></select>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.10/moment-timezone-with-data.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.min.js"></script>
<script>
var timezone = moment.tz.names();
for (var i = 0; i < timezone.length; i++) {
$('select').append('<option value="' + timezone[i] + '">' + timezone[i] + '</option>');
}
$('select').selectpicker();
</script>
</body>
</html>
@stefanRepac
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment