如何按偏移值对时区进行排序? [英] How do I sort timezone by offset value?
问题描述
< pre lang =text>< pre lang =text>< pre lang =text>
大家好对于我们如何根据偏移值对时区进行排序所需的帮助很少。简单来说,我得到了如下数组
你可以在这里查看代码。 http://jsfiddle.net/arunrajkhumar/2nvwzr6o/ [ ^ ]
输出看起来像这个,
(格林威治标准时间-2:0)大西洋/南乔治亚州
(格林威治标准时间-11:0)太平洋/中途岛
(格林威治标准时间-10) :0)Pacific / Rarotonga
(GMT + 3:0)非洲/阿斯马拉
(GMT + 2:0)非洲/布琼布拉
(格林尼治标准时间+5:45)亚洲/加德满都
(格林尼治标准时间+14:0)太平洋/ Kiritimati
(格林尼治标准时间+12:45)太平洋/查塔姆
(格林尼治标准时间+12:0)太平洋/瓦利斯
(格林尼治标准时间+11:30)太平洋/诺福克
(格林威治标准时间+12:45)太平洋/查塔姆
但问题是,它需要按顺序排序,如-12,-11,-10,... 0 ...... 1,2,3。 。+ 12 ..我们可以按此顺序下载windows os timezone。
我们怎样才能做到这一点?请分享您的想法。
您的时区数据不包含偏移值,因此您需要从标签中提取它。
这样的事情应该有效:
timeZone.sort( function (a,b){
var re = / ^ \(GMT([+ - ] \d { 1 , 2 }):( \d { 1 ,< span class =code-digit> 2 })\)。*
/;
var aOffset = parseFloat (a.label.replace(re,
1
<pre lang="text"><pre lang="text"><pre lang="text">
Hi All, little help needed on how we sort timezone based on the offset value. To put it simple, I got a array like below
you can check the code here. http://jsfiddle.net/arunrajkhumar/2nvwzr6o/[^]
The output looks like this,
(GMT-2:0) Atlantic/South_Georgia
(GMT-11:0) Pacific/Midway
(GMT-10:0) Pacific/Rarotonga
(GMT+3:0) Africa/Asmara
(GMT+2:0) Africa/Bujumbura
(GMT+5:45) Asia/Kathmandu
(GMT+14:0) Pacific/Kiritimati
(GMT+12:45) Pacific/Chatham
(GMT+12:0) Pacific/Wallis
(GMT+11:30) Pacific/Norfolk
(GMT+12:45) Pacific/Chatham
But the problem is, it needs to be sorted in order like -12, -11, -10, .. 0... 1,2,3 .. +12.. we can windows os timezone dropdown in this order.
How can we achieve this ? Please share your thoughts.
Your timezone data doesn't contain the offset value, so you'll need to extract it from the label.
Something like this should work:
timeZone.sort( function( a, b ) { var re = /^\(GMT([+-]\d{1,2}):(\d{1,2})\).*
/; var aOffset = parseFloat(a.label.replace(re, "
1.
这篇关于如何按偏移值对时区进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!