JQuery selects the corresponding instant time according to the city time zone

Source: Internet
Author: User

In our CRM system, the following is a time zone widget with jquery


Time Zone City
$ (function () {
All city and time static output
var Cityid = 170; China, Beijing
var showzone = $.showzone (Cityid);
$ ("#cityDate. Timeselect dd"). Live (' click ', Function (e) {
Cityid = $ (this). attr ("id");
$.showzone (Cityid);
// });
//});
(function ($) {
$.extend ({
"Showzone": function (ID) {

var city = new Array ([' Andorra Andorra ', ' a ', ' 1 '],[' Algeria Algiers ', ' a ', ' 2 '],[' Albania/Tirana ', ' A ', ' 3 '],[' Austria Vienna ', ' a ', ' 4 '],[' Australia Perth ', ' H ', ' 5 '],[' Australia Darwin ', ' I1 ', ' 6 '],[' Australia Brisben ', ' k ', ' 7 '],[' Australia • Melbourne ', ' K ', ' 8 '],[' Australia Queensland ', ' K ', ' 9 '],[' Australia Sydney ', ' K ', ' 10 '],[' Australia Adelaide ', ' K1 ', ' 11 '],[' UAE Abu Dhabi ', ' d ', ' 12 '],[' UAE Dubai ', ' d ', ' 13 '],[' Oman • Muscat ', ' d ', ' 14 '],[' Afghanistan Kabul ', ' D1 ', ' 15 '],[' Argentina • Buenos Aires ', ' P ', ' 16 '],[' Alaska • Anchorage ', ' V ', ' 17 '],[' Eniwetok ', ' Y ', ' 18 '],[' Egypt Cairo ', ' B ', ' 19 '],[' Ethiopia ', ' C ', ' 20 '] , [' Belgium • Brussels ', ' a ', ' 21 '],[' Poland Warsaw ', ' a ', ' 22 '],[' Gaberones ', ' B ', ' 23 '],[' Bulgaria Sofia ', ' B ', ' 24 '],[' Pakistan Islamabad ', ' E ', ' 25 '],[' Pakistan Karachi ', ' E ', ' 26 '],[' Brazil Brasilia ', ' P ', ' 27 '],[' Brazil • Rio ', ' P ', ' 28 '],[' Barbados • Bridgetown ', ' Q ', ' 29 '],[' Papua New Guinea ', ' K ', ' 30 ' Guinea ' Bermuda · Hamilton ', ' Q ', ' 31 '],[' Bolivian Lapaz ', ' Q ', ' 32 '],[' Paraguay • Asuncion ', ' Q ', ' 33 '],[' Bahamas • Nassau ', ' R ', ' 34 '],[' Panama City ', ' R ', ' 35 '],[' Iceland · Reykjavik ', ' Z ', ' 36 '],[' North Korea Pyongyang ', ' I ', ' 37 '],[' Germany • Berlin ', ' a ', ' 38 '],[' Denmark Copenhagen ', ' a ', ' 39 '],[' Germany • Frankfurt ', ' a ', ' 40 '],[' Germany • Hamburg ', ' a ', ' 41 '],[' Dar es Salaam ', ' C ', ' 42 '],[' Domincan Rep. ', ' Q ',' 43 '],[' Dominic Rosso ', ' Q ', ' 44 '],[' Russia Moscow ', ' C ', ' 45 '],[' Ecuador • Quito ', ' R ', ' 46 '],[' France Lyon ', ' A ', ' 47 '],[' France Paris ', ' a ', ' 48 '],[' Finland Helsinki ', ' B ', ' 49 '],[' Cape Verde/Playa ', ' N ', ' 50 '],[' philippines • Manila ', ' H ', ' 51 '],[' Fiji Suva ', ' M ', ' 52 '],[' Congo Brazzaville ', ' A ', ' 53 '],[' Columbia Pol ' , ' R ', ' 54 '],[' Guba Hava that ', ' R ', ' 55 '],[' Costa Rica • San Jose ', ' S ', ' 56 '],[' Gambir islands ', ' V ', ' 57 '],[' Holland Amsterdam ', ' a ', ' 58 '],[' Holland Rosso ', ' a ', ' 59 '],[' Netherlands Antilles ', ' Q ', ' 60 '],[' Honduras • Tegucigalpa ', ' S ', ' 61 '],[' Huisendi island ', ' K ', ' 62 '],[' Czech Bragg ', ' A ', ' 63 '],[' Zimbabwe • Harare ', ' B ', ' 64 ' ],[' Cambodia Village • Phnom Penh ', ' G ', ' 65 '],[' Kiribati ', ' M2 ', ' 66 '],[' Canada • Newfoundland Province ', ' P1 ', ' 67 '],[' Canada Nova Scotia ', ' Q ', ' 68 '],[' Canada Montreal ', ' R ', ' 69 '] , [' Canada • Ottawa ', ' r ', ' 70 '],[' Canada • Toronto ', ' R ', ' 71 '],[' Canada • Winnipeg ', ' S ', ' 72 '],[' Canada Edmonton ', ' T ', ' 73 '],[' Canada • Vancouver ', ' U ', ' 74 '],[' Ghana Accra ', ' Z ', ' 75 '],[' kerala Millon Yavin ', ' a ', ' 76 '],[' Kuwait Kuwait ', ' C ', ' 77 '],[' Kenya Naillot ', ' C ', ' 78 '],[' Luxembourg ', ' a ', ' 79 '],[' Lebanon Beirut ', ' B ', ' 80 '],[' Romania • Bucharest ', ' B ', ' 81 '],[' US-Maryland ', ' R ', ' 82 '],[' US-New Jersey ', ' r ', ' 83 '],[' US-New York ', ' R ', ' 84 '],[' USA • Philadelphia ', ' R ', ' 85 '],[' United States Washington ', ' R ', ' 86 '],[' American Chicago ', ' S ', ' 87 '],['United States Atlanta ', ' R ', ' 88 '],[' US • Boston ', ' R ', ' 89 '],[' US Dallas ', ' s ', ' 90 '],[' US Houston ', ' s ', ' 91 '],[' US Wisconsin ', ' s ', ' 92 '],[' US • Montana ', ' T ' , ' 93 '],[' USA • New Mexico ', ' t ', ' 94 '],[' US • San Diego ', ' t ', ' 95 '],[' US • california ', ' u ', ' 96 '],[' US • Las Vegas ', ' u ', ' 97 '],[' US • Los Angeles ', ' u ', ' 98 ' ],[' US San Francisco ', ' U ', ' 99 '],[' US Seattle ', ' u ', ' 100 '],[' USA • Hawaii ', ' W ', ' 101 '],[' US • Honolulu ', ' W ', ' 102 '],[' Malaysia • Kuala Lumpur ', ' H ', ' 103 '],[' Bangladesh Dhaka ', ' F ', ' 104 '],[' Burma ', ' F1 ', ' 105 '],[' secret Roux Lima ', ' R ', ' 106 '],[' Morocco Casablanca ', ' Z ', ' 107 '],[' Moroccan Rabat ', ' Z ', ' 108 '],[' Port Moresby ', ' K ', ' 109 '],[' Mexico Mexico City ', ' S ', ' 110 '],[' Nigeria • Abuja ', ' a ', ' 111 '],[' Norway Oslo ', ' a ', ' 112 '],[' South Africa Cape ', ' B ', ' 113 '],[' South Africa Johannesburg ', ' B ', ' 114 '],[' South Han Han City/Seoul ', ' I ', ' 115 '],[' Portugal • Lisbon ', ' Z ', ' 116 '],[' Rhise Burn ', ' a ', ' 117 '],[' Sweden Stockholm ', ' a ', ' 118 '],[' Switzerland Zurich ', ' a ', ' 119 '],[' Japan-Sapporo ', ' I ', ' 120 '],[' Japan-Tokyo ', ' I ', ' 121 '],[' Japan/Osaka ', ' I ', ' 122 '],[' Sultan of Kabul ', ' B ', ' 123 '],[' Chambia Lushaka ', ' B ', ' 124 ' ],[' Sepulus Nicosia ', ' B ', ' 125 '],[' Saudi Arabia Lee Jade ', ' C ', ' 126 '],[' Sri Lanka • Colombo ', ' F ', ' 127 '],[' Samoa ', ' M1 ', ' 128 '],[' Santo Domingo ', ' Q ', ' 129 '] , [' Salvador San Salvador ', ' S ', ' 130 '],[' Senegal ·Dakar ', ' Z ', ' 131 '],[' Bandar Seri Begawan ', ' H ', ' 132 '],[' turkey • Istanbul ', ' B ', ' 133 '],[' Tanzania ', ' C ', ' 134 '],[' Thailand • Bangkok ', ' g ', ' 135 '],[' Thailand-Phuket ', ' g ', ' 136 '],[' Trindade island ', ' O ', ' 137 '],[' Uganda Kampala ', ' C ', ' 138 '],[' Uruguay • Montevideo ', ' P ', ' 139 '],[' Willemstad ', ' Q ', ' 140 '],[' Guatemala • Guatemala City ', ' S ', ' 141 '],[' Brunei ', ' H ', ' 142 '],[' Spanish baba Barcelona ', ' a ', ' 143 '],[' Hungary • Budapest ', ' a ', ' 144 '],[' Spain Madrid ', ' a ', ' 145 '],[' Greek Athens ', ' B ', ' 146 '],[' Singapore ', ' H ', ' 147 '],[' New Zealand Wellington ', ' m ', ' 148 '],[' New Caledonia Noumea ', ' L ', ' 149 '],[' New Zealand • Oakland ', ' m ', ' 150 '],[' Italy Milan ', ' A ', ' 151 '],[' Italy • Rome ', ' A ', ' 152 '],[' Israel Jerusalem ', ' B ', ' 153 '],[' Addis Ababa ', ' C ', ' 154 '],[' also Men Sas that ', ' C ', ' 155 '],[' Iran Declan ', ' C1 ', ' 156 '],[' India Mumbai ', ' E1 ', ' 157 '],[' India Calcutta ', ' E1 ', ' 158 '],[' India New Delhi ', ' E1 ', ' 159 '],[' Vietnam • Hanoi ', ' G ', ' 160 '],[' Indonesia • Jakarta ', ' G ', ' 161 ', [' Jamaica • Kingstown ', ' R ', ' 162 '],[' UK • Aberdeen ', ' Z ', ' 163 '],[' UK Edinburgh ', ' Z ', ' 164 '],[' UK Glasgow ', ' Z ', ' 165 '],[' England • Liverpool ', ' Z ', ' 166 '],[' British London ', ' Z ', ' 167 '],[' UK Manchester ', ' z ', ' 168 '],[' UK • Newcastle ', ' Z ', ' 169 '],[' China Beijing ', ' h ', ' 170 '],[' China Chongqing ', ' h ', ' 171 '],[' China • Guangzhou ', ' H ' , ' 172 '],[' China Harbin ', ' h ', ' 173 '],[' China • Hong Kong ', ' h ', ' 174 '],[' China Macau ', ' H ', ' 175 '],[' China Nanjing ', ' h ', ' 176 '],[' China Shanghai ', ' h ', ' 177 '],[' China Taipei ', ' h ', ' 178 '],[' China Urumqi ', ' h ', ' 179 '],[' Midway Is. ', ' X ', ' 180 '],[' Chile Santiago ', ' Q ', ' 181 ']);

var zone = new Array ([' A ', ' 1 '],[' B ', ' 2 '],[' C ', ' 3 '],[' C1 ', ' 3.5 '],[' D ', ' 4 '],[' D1 ', ' 4.5 '],[' E ', ' 5 '],[' E1 ', ' 5.5 '],[' F ' , ' 6 '],[' F1 ', ' 6.5 '],[' G ', ' 7 '],[' H ', ' 8 '],[' I ', ' 9 '],[' I1 ', ' 9.5 '],[' K ', ' 12 '],[' K1 ', ' 10.5 '],[' L ', ' one by one '],[' M ', ' '],[ ' M1 ', ' 12.5 '],[' M2 ', '],[' N ', '-1 '],[' O ', '-2 '],[' P ', '-3 '],[' P1 ', ' -3.5 '],[' Q ', '-4 '],[' R ', '-5 '],[' S ', '-6 ',],[' T ', '-7 '],[' U ', '-8 '],[' V ', '-9 '],[' W ', ' -10 '],[' X ', ' -11 '],[' Y ', ' -12 '],[' Z ', ' 0 '];

HTML output
var cityhtml = "";
for (Var i=0;i<city.length;i++) {
var ct = city[i][0];
var aa= ct.replace (/\,/g, "+");
var s=ct.split (', ');
/*console.log (S[0]);
for (Var j=0;j<s.length;j++) {
var haha = s[j];
}*/
if (s[1]== undefined) {
S[1] = "";
}else{
S[1] = s[1] + ",";
//}
cityhtml + + + s[1] + "+ s[0" + "+" + city[i][1] + ",</dd>";
cityhtml + = "<dd id=" + city[i][0] + ">" + city[i][1] + "-" + city[i][2] + "</dd>";
cityhtml + = "<dd id=" + city[i][2] + ">" + city[i][2] + "-" + s[1] + s[0] + "</dd>";
cityhtml + = "<dd id=" + city[i][2] + ">" + city[i][0] + "</dd>";
}
$ (function () {
$ ("#cityDate. Timeselect"). HTML (cityhtml);
});

function Getlocaltime (cityzonenum) {
if (typeof cityzonenum!== ' number ') return;
var d = new Date ();
var len = D.gettime ();
var offset = D.gettimezoneoffset () * 60000;
var utctime = len + offset;

var dzone = new Date (utctime + 3600000 * cityzonenum);

var vyear = Dzone.getfullyear ();
var Vmon = dzone.getmonth () + 1;
var VDay = Dzone.getdate ();
var h = dzone.gethours ();
var m = dzone.getminutes ();
var se = dzone.getseconds ();

var p_d = (vmon<10? "0" + Vmon:vmon + "month" + (vday<10?) "0" + vday:vday) + "Day";
var p_w = "Week" + "Day 123456". Split ("") [Dzone.getday ()];
var p_t = (h<10? "0" + h:h) + ":" + (m<10? ") 0 "+ m:m) +": "+ (se<10?") 0 "+se:se);
var p_t = (h<10? "0" + h:h) + ":" + (m<10? ") 0 "+ m:m) +": "+ (se<10?") 0 "+se:se);

$ ("#cityDate H3. P_d "). Text (p_d);
$ ("#cityDate H3. P_w "). Text (P_W);
$ ("#cityDate H3. p_t "). Text (p_t);
}

for (Var i=0;i<city.length;i++) {

if (city[i][2] = = ID) {
$ ("#cityDate H3. P_c "). Text (city[i][0]); Default and selected city output

for (Var j=0;j<zone.length;j++) {
if (zone[j][0] = = City[i][1]) {
var id = zone[j][1];
var Timedo = Window.setinterval (function () {
Window.clearinterval (haha);
Getlocaltime (ID);
Console.log (ID);
},1000);

$ ("#cityDate. Timeselect dd"). Live (' click ', Function (e) {
Window.clearinterval (Timedo);
$ ("#cityDate H3. P_d, #cityDate H3. P_w, #cityDate H3. p_t "). Text ("---");
});
}
}
return false;
}else{
$ ("#cityDate. P_c "). HTML (" <em style= ' color:red ' >no this cityid</em> ");
}
}
}
});
}) (JQuery);

JQuery selects the corresponding instant time according to the city time zone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.