Skip to content

Instantly share code, notes, and snippets.

@matori
Created November 20, 2013 06:33
Show Gist options
  • Save matori/7558692 to your computer and use it in GitHub Desktop.
Save matori/7558692 to your computer and use it in GitHub Desktop.
タイムゾーン短縮名からタイムゾーンオフセットを取得する
function tzAbbrToOffset(string) {
var timeZoneAbbr = ['ACDT', 'ACST', 'ACT', 'ADT', 'AEDT', 'AEST', 'AFT', 'AKDT', 'AKST', 'AMST', 'AMST', 'AMT', 'AMT', 'ART', 'AST', 'AST', 'AWDT', 'AWST', 'AZOST', 'AZT', 'BDT', 'BIOT', 'BIT', 'BOT', 'BRT', 'BST', 'BST', 'BTT', 'CAT', 'CCT', 'CDT', 'CDT', 'CEDT', 'CEST', 'CET', 'CHADT', 'CHAST', 'CHOT', 'ChST', 'CHUT', 'CIST', 'CIT', 'CKT', 'CLST', 'CLT', 'COST', 'COT', 'CST', 'CST', 'CST', 'CST', 'CST', 'CT', 'CVT', 'CWST', 'CXT', 'DAVT', 'DDUT', 'DFT', 'EASST', 'EAST', 'EAT', 'ECT', 'ECT', 'EDT', 'EEDT', 'EEST', 'EET', 'EGST', 'EGT', 'EIT', 'EST', 'EST', 'FET', 'FJT', 'FKST', 'FKST', 'FKT', 'FNT', 'GALT', 'GAMT', 'GET', 'GFT', 'GILT', 'GIT', 'GMT', 'GST', 'GST', 'GYT', 'HADT', 'HAEC', 'HAST', 'HKT', 'HMT', 'HOVT', 'HST', 'ICT', 'IDT', 'IOT', 'IRDT', 'IRKT', 'IRST', 'IST', 'IST', 'IST', 'JST', 'KGT', 'KOST', 'KRAT', 'KST', 'LHST', 'LHST', 'LINT', 'MAGT', 'MART', 'MAWT', 'MDT', 'MET', 'MEST', 'MHT', 'MIST', 'MIT', 'MMT', 'MSK', 'MST', 'MST', 'MST', 'MUT', 'MVT', 'MYT', 'NCT', 'NDT', 'NFT', 'NPT', 'NST', 'NT', 'NUT', 'NZDT', 'NZST', 'OMST', 'ORAT', 'PDT', 'PET', 'PETT', 'PGT', 'PHOT', 'PHT', 'PKT', 'PMDT', 'PMST', 'PONT', 'PST', 'PYST', 'PYT', 'RET', 'ROTT', 'SAKT', 'SAMT', 'SAST', 'SBT', 'SCT', 'SGT', 'SLST', 'SRT', 'SST', 'SST', 'SYOT', 'TAHT', 'THA', 'TFT', 'TJT', 'TKT', 'TLT', 'TMT', 'TOT', 'TVT', 'UCT', 'ULAT', 'UTC', 'UYST', 'UYT', 'UZT', 'VET', 'VLAT', 'VOLT', 'VOST', 'VUT', 'WAKT', 'WAST', 'WAT', 'WEDT', 'WEST', 'WET', 'WST', 'YAKT', 'YEKT', 'Z'];
var offset = ['+10:30', '+09:30', '+08:00', '-03:00', '+11:00', '+10:00', '+04:30', '-08:00', '-09:00', '-03:00', '+05:00', '-04:00', '+04:00', '-03:00', '+03:00', '-04:00', '+09:00', '+08:00', '-01:00', '+04:00', '+08:00', '+06:00', '-12:00', '-04:00', '-03:00', '+06:00', '+01:00', '+06:00', '+02:00', '+06:30', '-05:00', '-04:00', '+02:00', '+02:00', '+01:00', '+13:45', '+12:45', '+08:00', '+10:00', '+10:00', '-08:00', '+08:00', '-10:00', '-03:00', '-04:00', '-04:00', '-05:00', '-06:00', '+08:00', '+09:30', '+10:30', '-05:00', '+08:00', '-01:00', '+08:45', '+07:00', '+07:00', '+10:00', '+01:00', '-05:00', '-06:00', '+03:00', '-04:00', '-05:00', '-04:00', '+03:00', '+03:00', '+02:00', '+00:00', '-01:00', '+09:00', '-05:00', '+10:00', '+03:00', '+12:00', '-03:00', '-03:00', '-04:00', '-02:00', '-06:00', '-09:00', '+04:00', '-03:00', '+12:00', '-09:00', '+00:00', '-02:00', '+04:00', '-04:00', '-09:00', '+02:00', '-10:00', '+08:00', '+05:00', '+07:00', '-10:00', '+07:00', '+03:00', '+03:00', '+08:00', '+09:00', '+03:30', '+05:30', '+01:00', '+02:00', '+09:00', '+06:00', '+11:00', '+07:00', '+09:00', '+10:30', '+11:00', '+14:00', '+12:00', '-09:30', '+05:00', '-06:00', '+01:00', '+02:00', '+12:00', '+11:00', '-09:30', '+06:30', '+04:00', '+08:00', '-07:00', '+06:30', '+04:00', '+05:00', '+08:00', '+11:00', '-02:30', '+11:30', '+05:45', '-03:30', '-03:30', '-11:00', '+13:00', '+12:00', '+07:00', '+05:00', '-07:00', '-05:00', '+12:00', '+10:00', '+13:00', '+08:00', '+05:00', '-02:00', '-03:00', '+11:00', '-08:00', '-03:00', '-04:00', '+04:00', '-03:00', '+11:00', '+04:00', '+02:00', '+11:00', '+04:00', '+08:00', '+05:30', '-03:00', '-11:00', '+08:00', '+03:00', '-10:00', '+07:00', '+05:00', '+05:00', '+14:00', '+09:00', '+05:00', '+13:00', '+12:00', '+00:00', '+08:00', '+00:00', '-02:00', '-03:00', '+05:00', '-04:30', '+10:00', '+04:00', '+06:00', '+11:00', '+12:00', '+02:00', '+01:00', '+01:00', '+01:00', '+00:00', '+08:00', '+10:00', '+06:00', '+00:00'];
var msecOffset = [37800000, 34200000, 28800000, -10800000, 39600000, 36000000, 16200000, -28800000, -32400000, -10800000, 18000000, -14400000, 14400000, -10800000, 10800000, -14400000, 32400000, 28800000, -3600000, 14400000, 28800000, 21600000, -43200000, -14400000, -10800000, 21600000, 3600000, 21600000, 7200000, 23400000, -18000000, -14400000, 7200000, 7200000, 3600000, 49500000, 45900000, 28800000, 36000000, 36000000, -28800000, 28800000, -36000000, -10800000, -14400000, -14400000, -18000000, -21600000, 28800000, 34200000, 37800000, -18000000, 28800000, -3600000, 31500000, 25200000, 25200000, 36000000, 3600000, -18000000, -21600000, 10800000, -14400000, -18000000, -14400000, 10800000, 10800000, 7200000, 0, -3600000, 32400000, -18000000, 36000000, 10800000, 43200000, -10800000, -10800000, -14400000, -7200000, -21600000, -32400000, 14400000, -10800000, 43200000, -32400000, 0, -7200000, 14400000, -14400000, -32400000, 7200000, -36000000, 28800000, 18000000, 25200000, -36000000, 25200000, 10800000, 10800000, 28800000, 32400000, 12600000, 19800000, 3600000, 7200000, 32400000, 21600000, 39600000, 25200000, 32400000, 37800000, 39600000, 50400000, 43200000, -34200000, 18000000, -21600000, 3600000, 7200000, 43200000, 39600000, -34200000, 23400000, 14400000, 28800000, -25200000, 23400000, 14400000, 18000000, 28800000, 39600000, -9000000, 41400000, 20700000, -12600000, -12600000, -39600000, 46800000, 43200000, 25200000, 18000000, -25200000, -18000000, 43200000, 36000000, 46800000, 28800000, 18000000, -7200000, -10800000, 39600000, -28800000, -10800000, -14400000, 14400000, -10800000, 39600000, 14400000, 7200000, 39600000, 14400000, 28800000, 19800000, -10800000, -39600000, 28800000, 10800000, -36000000, 25200000, 18000000, 18000000, 50400000, 32400000, 18000000, 46800000, 43200000, 0, 28800000, 0, -7200000, -10800000, 18000000, -16200000, 36000000, 14400000, 21600000, 39600000, 43200000, 7200000, 3600000, 3600000, 3600000, 0, 28800000, 36000000, 21600000, 0];
var index = timeZoneAbbr.indexOf(string);
return {
time: offset[index],
msec: msecOffset[index]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment