World Time Conversion
PowerShell v3+, 71 bytes
param($a,$b,$x)$b|%{$y=$x[$_];"{0:t} $($y[1])"-f(date $a).AddHours($y[0])}
(74 bytes, -3 bytes for input ,$x
, the dictionary of country->timezone conversions, equals 71 bytes)
Uses the below dictionary/hashtable for the timezone conversion, which I manually created (with some creative Excel, PowerShell, and Ctrl-H help) based on the Wikipedia link.
$x=@{'France'=(1,'CET');'United States'=(-5,'EST');'Russia'=(3,'Moscow');'United Kingdom'=(0,'UTC');'Australia'=(10,'AEST');'Canada'=(-5,'EST');'Kingdom of Denmark'=(1,'CET');'New Zealand'=(12,'NZST');'Brazil'=(-3,'BRT');'Mexico'=(-6,'Zona Centro');'Indonesia'=(7,'WIST');'Kiribati'=(12,'Gilbert');'Chile'=(-3,'CLT');'Democratic Republic of the Congo'=(1,'WAT');'Ecuador'=(-5,'Ecuador Time');'Federated States of Micronesia'=(11,'Kosrae');'Kazakhstan'=(6,'Almaty');'Kingdom of the Netherlands'=(1,'CET');'Mongolia'=(8,'Ulaanbaatar');'Papua New Guinea'=(10,'AEST');'Portugal'=(0,'WET');'South Africa'=(2,'SAST');'Spain'=(1,'CET');'Afghanistan'=(4.5,'Afghanistan');'Albania'=(1,'CET');'Algeria'=(1,'CET');'Andorra'=(1,'CET');'Angola'=(1,'WAT');'Antigua and Barbuda'=(-4,'AST');'Argentina'=(-3,'ART');'Armenia'=(4,'');'Austria'=(1,'CET');'Azerbaijan'=(4,'');'Bahamas'=(-5,'EST');'Bahrain'=(3,'');'Bangladesh'=(6,'BDT');'Barbados'=(-4,'');'Belarus'=(3,'FET');'Belgium'=(1,'CET');'Belize'=(-6,'');'Benin'=(1,'WAT');'Bhutan'=(6,'BTT');'Bolivia'=(-4,'');'Bosnia and Herzegovina'=(1,'CET');'Botswana'=(2,'CAT');'Brunei'=(8,'');'Bulgaria'=(2,'EET');'Burkina Faso'=(0,'UTC');'Burundi'=(2,'CAT');'Cambodia'=(7,'');'Cameroon'=(1,'WAT');'Cape Verde'=(-1,'CVT');'Central African Republic'=(1,'WAT');'Chad'=(1,'WAT');'China'=(8,'Chinese Standard Time');'Colombia'=(-5,'');'Comoros'=(3,'EAT');'Republic of the Congo'=(1,'WAT');'Costa Rica'=(-6,'');'Croatia'=(1,'CET');'Cuba'=(-5,'');'Cyprus'=(2,'EET');'Czech Republic'=(1,'CRT');'Djibouti'=(3,'EAT');'Dominica'=(-4,'');'Dominican Republic'=(-4,'');'East Timor'=(9,'');'Egypt'=(2,'EET');'El Salvador'=(-6,'');'Equatorial Guinea'=(1,'WAT');'Eritrea'=(3,'EAT');'Estonia'=(2,'EET');'Ethiopia'=(3,'EAT');'Fiji'=(12,'');'Finland'=(2,'EET');'Gabon'=(1,'WAT');'Gambia'=(0,'GMT');'Georgia'=(4,'');'Germany'=(1,'CET');'Ghana'=(0,'GMT');'Greece'=(2,'EET');'Grenada'=(-4,'');'Guatemala'=(-6,'');'Guinea'=(0,'GMT');'Guinea-Bissau'=(0,'GMT');'Guyana'=(-4,'');'Haiti'=(-5,'');'Honduras'=(-6,'');'Hong Kong'=(8,'HKT');'Hungary'=(1,'CET');'Iceland'=(0,'GMT');'India'=(5.5,'IST');'Iran'=(3.5,'IRST');'Iraq'=(3,'');'Ireland'=(0,'WET');'Israel'=(2,'IST');'Italy'=(1,'CET');'Ivory Coast'=(0,'GMT');'Jamaica'=(-5,'');'Japan'=(9,'JST');'Jordan'=(2,'');'Kenya'=(3,'EAT');'North Korea'=(8.5,'Pyongyang');'South Korea'=(9,'KST');'Kuwait'=(3,'AST');'Kosovo'=(1,'');'Kyrgyzstan'=(6,'');'Laos'=(7,'');'Latvia'=(2,'EET');'Lebanon'=(2,'EET');'Lesotho'=(2,'');'Liberia'=(0,'GMT');'Libya'=(2,'EET');'Liechtenstein'=(1,'CET');'Lithuania'=(2,'EET');'Luxembourg'=(1,'CET');'Macau (China)'=(8,'Macau');'Macedonia'=(1,'CET');'Madagascar'=(3,'EAT');'Malawi'=(2,'CAT');'Malaysia'=(8,'Malaysia');'Maldives'=(5,'');'Mali'=(0,'GMT');'Malta'=(1,'CET');'Marshall Islands'=(12,'');'Mauritania'=(0,'GMT');'Mauritius'=(4,'Mauritius');'Moldova'=(2,'EET');'Monaco'=(1,'CET');'Montenegro'=(1,'CET');'Morocco'=(0,'WET');'Mozambique'=(2,'CAT');'Myanmar'=(6.5,'MST');'Namibia'=(1,'WAT');'Nauru'=(12,'');'Nepal'=(5.75,'Nepal');'Nicaragua'=(-6,'');'Niger'=(1,'WAT');'Nigeria'=(1,'WAT');'Norway'=(1,'CET');'Oman'=(4,'');'Pakistan'=(5,'PKT');'Palau'=(9,'');'Panama'=(-5,'');'Paraguay'=(-4,'');'Peru'=(-5,'PET');'Philippines'=(8,'PHT');'Poland'=(1,'CET');'Qatar'=(3,'AST');'Romania'=(2,'EET');'Rwanda'=(2,'CAT');'Saint Kitts and Nevis'=(-4,'');'Saint Lucia'=(-4,'');'Saint Vincent and the Grenadines'=(-4,'');'Samoa'=(13,'');'San Marino'=(1,'CET');'São Tomé and Príncipe'=(0,'GMT');'Saudi Arabia'=(3,'AST');'Senegal'=(0,'GMT');'Serbia'=(1,'CET');'Seychelles'=(4,'Seychelles');'Sierra Leone'=(0,'GMT');'Singapore'=(8,'SST');'Slovakia'=(1,'CET');'Slovenia'=(1,'CET');'Solomon Islands'=(11,'');'Somalia'=(3,'EAT');'South Sudan'=(3,'EAT');'Sri Lanka'=(5.5,'SLST');'Sudan'=(3,'EAT');'Suriname'=(-3,'');'Swaziland'=(2,'');'Sweden'=(1,'CET');'Switzerland'=(1,'CET');'Syria'=(2,'EET');'Taiwan'=(8,'');'Tajikistan'=(5,'');'Tanzania'=(3,'EAT');'Thailand'=(7,'THA');'Togo'=(0,'GMT');'Tonga'=(13,'');'Trinidad and Tobago'=(-4,'');'Tunisia'=(1,'CET');'Turkey'=(2,'EET');'Turkmenistan'=(5,'');'Tuvalu'=(12,'');'Uganda'=(3,'EAT');'Ukraine'=(2,'EET');'United Arab Emirates'=(4,'');'Uruguay'=(-3,'');'Uzbekistan'=(5,'Uzbekistan');'Vanuatu'=(11,'');'Vatican City'=(1,'CET');'Venezuela'=(-4,'');'Vietnam'=(7,'Indochina');'Yemen'=(3,'');'Zambia'=(2,'CAT');'Zimbabwe'=(2,'CAT')}
Takes input $a
as a string in 24hr format, $b
as an explicit array of strings, and the dictionary $x
. Loops through $b
, and for each creates a new Date
based on $a
, then calls .AddHours
, indexing into the dictionary to determine how many, and uses the -f
ormat operator to pull out the correct information.
Example
PS C:\Tools\Scripts\golfing> .\world-time-conversion.ps1 '12:00' @('United States','Italy','Russia','Nepal') $x
7:00 AM EST
1:00 PM CET
3:00 PM Moscow
5:45 PM Nepal
Python 2, 154 153 151 148 147 138 134 131 123 121 116 bytes
-4 bytes thanks to @Shebang (missed a div //
to /
Py3 -> Py2 conversion; print time zone using unpacking; use map to replace two int
casts)
def f(t,c,d):
for x in c:a,b=map(int,t.split(':'));e,z=d[x];v=60*a+b+e;print`v/60%12`+':'+`v%60`,'pa'[v%1440<720],z
repl.it (I only bothered with a tiny subset of countries, as that's a chore and I'm lazy - but I included Nepal to have a non-standard offset in there & Tuvalu with it's +12:00 one).
Input is t
the time string in 24 hr format; c
the list of countries; and d
a dictionary of country string to tuple of minutes offset and time zone name.
Prints a 12hr format plus time zone for each country split by new lines. Leading zeros are not printed AM
/PM
indicator is just a
/p
(e.g. 08:06 in Nepal prints as 8:6 a Nepal Time
)
bash (126 bytes)
w(){ cd /u*/sh*/z*
join -o2.2 <(egrep "$2" i*) <(cut -sf1,3 zone.*)|while read z
do TZ=$z date -d"UTC$1" +"%z %r";done|uniq;}
w 12:00PM "United States|Italy|Russia"
uses GNU date and file:/usr/share/zoneinfo/{iso3166,zone}.tab