百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

timezone-picker

> 编程语言
开源

使用世界地图选择时区

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用世界地图选择时区

timezone-picker

timezone-picker is the plugin to select and get timezone value of selected area(country) from WorldMap.

Live Demo: http://kevalbhatt.github.io/timezone-picker/


Dependency


  • moment-timezone
  • jquery
  • select2 (optional)

Installation


Use package Using npm

bash
npm install --save timezone-picker

or

Use package Using CDN

xml

Include the following lines of code in the section of your HTML.

xml
 

 

 

Usage


Select any dom element where you want to create the map.

javascript
$(selector).timezonePicker();

defaultValue

Set a custom value on load

If defaultValue is null then system timezone is selected

  • Select value based on zonename.

javascript
$(selector).timezonePicker({ defaultValue: { value: "EAT", attribute: "zonename" }});
  • Select value based on country code.

javascript
$(selector).timezonePicker({ defaultValue: { value: "IN", attribute: "country" }});
  • Select value based on timezone.

javascript
$(selector).timezonePicker({ defaultValue: { value: "Asia/Calcutta", attribute: "timezone" }});
  • Select value based on offset.

javascript
$(selector).timezonePicker({ defaultValue: { value: "5.5", attribute: "offset" }});

quickLink

You can create custom shortcuts link using quickLink options.

javascript
$(selector).timezonePicker({
    quickLink: [{
        "IST": "IST",
        "LONDON": "Europe/London"
    }]
});
  • "LONDON": This key is used as a display string for shortcut button.
  • "Europe/London": This value is used when user click on a button and based on value, map is highlighted

Example:

You can pass following value.

  • timezone : Europe/London
  • zonename : GMT
  • country code : GB
javascript
$(selector).timezonePicker({
    quickLink: [{
        "LONDON1": "Europe/London"
    }]
});

$(selector).timezonePicker({
    quickLink: [{
        "LONDON2": "GB"
    }]
});

$(selector).timezonePicker({
    quickLink: [{
        "LONDON3": "GMT"
    }]
});

$(selector).timezonePicker({
    quickLink: [{
        "GMT": "GMT"
    }]
});

hoverText

javascript
$(selector).timezonePicker({
    hoverText: function(e, data){
        return (data.timezone + " (" + data.zonename + ")");
    }
});

quickLinkClass

Class name for the quickLink container.

javascript
$(selector).timezonePicker({
    quickLinkClass: "quick-class"
});

Output

diff

    

selectClass

Class name for the country drop-down.

javascript
$('body').timezonePicker({
    selectClass: "select-class"
});

Output

diff

    

filterBoxClass

Class name for the filter box container.

javascript
$('body').timezonePicker({
    filterBoxClass: "filter-class"
});

Output

diff
+

    

hoverTextClass

Class name for the hover text container.

javascript
$('body').timezonePicker({
    hoverTextClass: "hover-class"
});

Output

diff

+    

Options


Parameter Type Default Description
width Number 500 width of map
height Number 250 height of map
defaultValue Object System timezone Set custome value on load { value: "EAT", attribute: "zonename" }
quickLink Array [{"IST": "IST","LONDON": "Europe/London"}] Creates shortcuts to select zone
quickLinkClass String quick-link quickLinkClass will be appended with the default value
filterBoxClass String filter-box filterBoxClass will be appended with the default value
selectBox Boolean true If it is set to false select box will not be created
selectClass String country-lov selectClass is appended with the default value
showHoverText Boolean true If it is set to false hover text will not be shown
hoverText Function timezone(zonename) Called on hover of country (works only if showHoverText is true)
hoverTextClass String hover-text hoverTextClass is appended with the default value
hoverTextEl Jquery selector Appened in filter-box hover text element is appended in selector
mapHoverType String hover polygon(area) by default it will show hovered polygon(area) on which mouse is pointed other hover options

mapHoverType options

Parameter Type Description
timezone String when you hover on the map it will highlight all country with the same timezone
country String when you hover on the map it will highlight all country with same country code
zonename String when you hover on the map it will highlight all country with the same zone name

Methods


.setValue(value[String-required],attribute[String-optional])

Select the value(country) based on value and attribute parameter.

  • Set timezone string as a first parameter for example: 'Asia/Kolkata'.
  • Default attribute is "timezone";
javascript
$(selector).data('timezonePicker').setValue('Asia/Kolkata')
  • If you want to set value based on offset then set the 1st parameter as an offset string("5.5") and 2nd parameter to 'offset'
javascript
$(selector).data('timezonePicker').setValue('5.5','offset')
  • If you want to set value based country code then set the 1st parameter as country code and 2nd parameter to 'country'
javascript
$(selector).data('timezonePicker').setValue('IN','country')
  • If you want to set value based zonename then set the 1st parameter as zonename(IST) and 2nd parameter to 'zonename'
javascript
$(selector).data('timezonePicker').setValue('IST','zonename')

.getValue()

It returns object containing timezone details of seleted area:

javascript
$(selector).data('timezonePicker').getValue()

Sample returned Object

javascript
  [
    {
        "selected":true,
        "zonename":"IST",
        "offset":5.5,
        "pin":"361,115",
        "country":"LK",
        "timezone": "Asia/Colombo",
    },
    {
        "zonename":"IST",
        "offset":5.5,
        "pin": "373,94",
        "country":"IN",
        "timezone": "Asia/Kolkata",
    }
]

.getSystemTimezone()

It returns an object containing system timezone details.

.getTimeZoneObject(value[String-required],attribute[String-optional])

It returns an object containing timezone details based on value and attribute.

  • Get timezone Object using timezone string example: 'Asia/Kolkata'.
  • Default attribute is "timezone";
javascript
$(selector).data('timezonePicker').getTimeZoneObject('Asia/Kolkata');
  • If you want to get Object based on offset then set the 1st parameter as an offset string("5.5") and 2nd parameter to 'offset'
javascript
$(selector).data('timezonePicker').getTimeZoneObject('5.5','offset');
  • If you want to get Object based country code then set the 1st parameter as country code and 2nd parameter to 'country'
javascript
$(selector).data('timezonePicker').getTimeZoneObject('IN','country');
  • If you want to get Object based zonename then set the 1st parameter as zonename(IST) and 2nd parameter to 'zonename'
javascript
$(selector).data('timezonePicker').getTimeZoneObject('IST','zonename');

.getZoneName(value[String-required],attribute[String-optional])

It returns an zonename based on value and attribute.

  • Get zonename String using timezone string example: 'Asia/Kolkata'.
  • Default attribute is "timezone";
javascript
$(selector).data('timezonePicker').getZoneName('Asia/Kolkata');
  • If you want to get zonename based on offset then set the 1st parameter as an offset string("5.5") and 2nd parameter to 'offset'
javascript
$(selector).data('timezonePicker').getZoneName('5.5','offset');
  • If you want to get zonename based country code then set the 1st parameter as country code and 2nd parameter to 'country'
javascript
$(selector).data('timezonePicker').getZoneName('IN','country');

.getTimeZoneString(value[String-required],attribute[String-optional])

It returns an timezone string based on value and attribute.

  • Get timezone String using country code example: 'IN'.
  • Default attribute is "country";
javascript
$(selector).data('timezonePicker').getZoneName('IN');
  • If you want to get timezone string based on offset then set the 1st parameter as an offset string("5.5") and 2nd parameter to 'offset'
javascript
$(selector).data('timezonePicker').getTimeZoneString('5.5','offset');
  • If you want to get timezone string based zonename then set the 1st parameter as zonename(IST) and 2nd parameter to 'zonename'
javascript
$(selector).data('timezonePicker').getTimeZoneString('IST','zonename');

Events


map:loaded

As soon as the map is loaded and ready the map:loaded is fired. To catch it you can use:

$(selector).on("map:loaded" , function(){
    console.log("Map is loaded, have fun!");
});

map:value:changed

Whenever the value of the timezone changes, the event map:value:changed is fired. To catch it you can use:

$(selector).on("map:value:changed" , function(){
    console.log($(selector).data('timezonePicker').getValue());
});

map:country:clicked

Event map:country:clicked is fired, when a user clicks on the country. To catch it you can use:

$(selector).on("map:country:clicked" , function(){
    console.log($(selector).data('timezonePicker').getValue());
});

map:quickLink:clicked

Event map:quickLink:clicked is fired, when a user clicks on the quickLink button. To catch it you can use:

$(selector).on("map:quickLink:clicked" , function(){
    console.log($(selector).data('timezonePicker').getValue());
});

map:option:changed

Event map:option:changed is fired, when a user changes the value from the country drop-down. To catch it you can use:

$(selector).on("map:option:changed" , function(){
    console.log($(selector).data('timezonePicker').getValue());
});

License


It is available under the MIT LICENSE

Issues· 31 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptcountrycountry-dropjqueryjquery-timezone

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言