Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Last active March 9, 2024 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vadimkantorov/4ab05ea6bb328eda7517fd78dc26fd83 to your computer and use it in GitHub Desktop.
Save vadimkantorov/4ab05ea6bb328eda7517fd78dc26fd83 to your computer and use it in GitHub Desktop.
Given a list of "lat,lng" prints a local timestamp (20h) in all of the timezones
# python -m pip install timezonefinder pytz --user
import timezonefinder
import pytz
import datetime
latlnglist = '''
43.0010092,41.0208743
42.9972303,41.0089412
43.0125911,40.9705287
42.9991332,41.0408331
43.3816433,40.0827413
43.2973744,40.2581868
43.1592557,40.3381064
43.2737354,40.278336
43.0032187,41.0159445
43.1012373,40.6157918
43.139777,40.6180193
43.0891968,40.8125015
43.0400325,40.9341606
43.1004237,41.416138
43.1004237,41.416138
43.01490200000001,40.98533399999999
43.0070161,41.0079879
42.7082626,41.4661503
43.0015252,41.0234153
43.2717517,40.2686784
42.7082626,41.4661503
42.7962214,41.5395805
42.8555321,41.6734319
42.9737816,41.4421799
42.6259555,41.73491689999999
42.9737816,41.4421799
42.9737816,41.4421799
42.9470269,41.0862267
42.9737816,41.4421799
42.8786984,41.4914772
-35.3206148,149.1385381
-33.8815526,151.2393885
48.1941134,16.3953555
47.7986604,13.0559441
40.3876481,49.830213
41.3275459,19.8186982
36.753768,3.0587561
-8.8146556,13.2301756
-34.5907443,-58.3886374
40.1753995,44.5045262
40.069099,45.038189
40.7929026,43.8464971
40.069099,45.038189
40.069099,45.038189
34.5553494,69.207486
37.2146169,67.4188723
23.7924961,90.40780579999999
26.2235305,50.5875935
53.9259795,27.5433013
52.0948405,23.6876086
53.6865262,23.835585
55.1926809,30.206359
52.4539911,30.9970727
53.90435,30.3431445
53.709807,27.953389
50.8476424,4.3571696
6.3562425,2.4277995
42.6702524,23.3452574
-16.489689,-68.11929359999999
43.8562586,18.4130763
-24.6456783,25.9175737
-15.8252294,-47.8909117
-22.9842698,-43.223168
-23.5557714,-46.6395571
4.8826698,114.9442708
-3.3806433,29.3655886
51.5077869,-0.1908975
47.5133276,19.0745503
18.971187,-72.285215
21.0277644,105.8341598
10.7775505,106.6878981
16.0544068,108.2021667
10.3599989,107.0813927
0.391782,9.4517511
6.8012793,-58.1551255
5.559284600000001,-0.1974306
14.6349149,-90.5068824
11.8632196,-15.5843227
9.5090945,-13.7119312
37.9838096,23.7275388
40.6400629,22.9444191
55.6760968,12.5683371
-4.334949,15.2382386
11.5885948,43.14536469999999
30.0444196,31.2357116
31.2375442,29.9556722
27.1557334,33.8262967
-15.4154677,28.2773267
-13.254308,34.301525
32.0630851,34.7622228
31.7828701,35.2221604
32.8158903,34.9900149
28.6353843,77.1025801
18.9257282,72.8230219
22.5179128,88.3283117
13.0826802,80.2707184
15.4909301,73.8278496
-6.1944491,106.8229198
31.9539494,35.910635
33.3407449,44.388752
30.5257657,47.77379699999999
36.190073,43.9930303
35.7218583,51.3346954
37.2712671,49.5920736
32.652396,51.6687024
28.9144913,50.8279019
32.427908,53.688046
53.3040308,-6.2595798
64.1431613,-21.937521
40.4440975,-3.683238
41.3873974,2.168568
41.9027835,12.4963655
45.4642035,9.189982
44.4056499,8.946256
38.11569,13.3614868
14.919775,-23.5073437
51.1653583,71.42360959999999
51.1653583,71.42360959999999
49.9498038,82.62557679999999
46.031113,73.7015195
43.23593169999999,76.9114584
43.2364035,76.8903842
51.2118228,51.3818755
11.5563738,104.9282099
1.650801,10.267895
4.0531425,9.699582300000001
3.7549606,8.7821344
45.4297804,-75.6734073
45.5018869,-73.56739189999999
43.6874845,-79.3930467
25.2598356,51.61430259999999
-1.2887681,36.7943515
35.1855659,33.38227639999999
35.1657789,33.3405044
42.8741519,74.58852460000001
41.20438,74.766098
41.20438,74.766098
40.5139985,72.81609759999999
39.0392193,125.7625241
41.7669671,129.723402
39.904211,116.407395
31.24388,121.490866
41.6352665,123.496524
22.2762468,114.1825781
23.1290799,113.26436
45.749405,126.637632
4.6510495,-74.0541975
9.937315199999999,-84.0629919
5.3599517,-4.0082563
23.1210808,-82.4226331
29.375859,47.9774052
17.9757058,102.6331035
56.9570399,24.1093342
56.9570399,24.1093342
56.95881499999999,24.118998
33.883916,35.48333
32.8877109,13.187186
54.6719005,25.2619014
49.6433733,6.137760800000001
-20.348404,57.55215200000001
18.0735299,-15.9582372
-18.9184607,47.5211293
3.16648,101.7483451
12.617098,-7.981084500000001
35.9078199,14.4854324
34.0083637,-6.8538748
33.5777609,-7.629152500000001
19.4089477,-99.1802147
-26.522503,31.465866
47.0319775,28.8202095
47.9220509,106.9155007
49.482171,105.92296
16.840939,96.173526
-22.5649344,17.0842147
27.7172453,85.3239605
9.0528755,7.5280916
52.0704978,4.3006999
12.1149926,-86.2361744
-41.2923814,174.7787463
59.91292790000001,10.7054877
69.7269192,30.0450432
78.0648475,14.2334595
24.453884,54.3773438
25.2048493,55.2707828
23.5880307,58.3828717
33.5530834,73.1365962
24.8593999,67.07640959999999
31.9037641,35.2034184
8.9823792,-79.51986959999999
-25.2769152,-57.56551839999999
-12.0463731,-77.042754
52.2131463,21.0276429
54.3857784,18.5794609
50.06740749999999,19.959082
52.406374,16.9251681
38.720114,-9.145823
-4.2744405,15.2812803
37.5601443,126.9959649
35.1060903,129.0366472
-1.9506866,30.0625213
44.452444,26.0856777
44.6449021,28.6786272
24.7135517,46.6752957
21.5291545,39.1610863
41.9995121,21.4240831
-4.621129799999999,55.4522153
14.716677,-17.4676861
44.8125449,20.46123
1.352083,103.819836
33.5132192,36.2768193
48.1485965,17.1077477
46.0569465,14.5057515
38.9240926,-77.0744117
40.7845385,-73.9569808
29.7549154,-95.4545821
19.4344033,37.2383915
38.573694,68.7550755
38.861034,71.276093
38.861034,71.276093
38.861034,71.276093
38.861034,71.276093
40.295192,69.6262039
13.7262438,100.5281812
7.8804479,98.3922504
-6.8003606,39.2872101
36.8344193,10.1521041
37.9600766,58.32606289999999
38.969719,59.556278
38.969719,59.556278
38.969719,59.556278
39.99979099999999,52.9701611
39.8451842,32.9212265
41.0040106,39.7198664
36.8827757,30.7694759
41.02992,28.9755151
0.3151692,32.5816313
41.285271,69.2705721
39.7680827,64.4555769
-34.9055016,-56.1851147
52.51632,13.3839
50.6850639,7.1323744
14.554729,121.0244452
60.16985569999999,24.938379
48.8664721,2.2710745
43.7041186,7.310538399999999
43.296482,5.36978
48.58666909999999,7.762962199999999
45.8150108,15.981919
4.362156,18.5827765
12.1286595,15.0327834
42.4304196,19.2593642
50.1025749,14.4160943
-33.3948705,-70.5891239
46.9345685,7.463273
46.2043907,6.1431577
59.32932349999999,18.0685808
6.9270786,79.861243
-0.1806532,-78.4678382
-2.156738,-79.8971085
15.2925537,38.9123957
59.4386385,24.7445814
9.037087099999999,38.8100855
42.2214597,43.9644051
42.2214597,43.9644051
42.2214597,43.9644051
42.2214597,43.9644051
42.3842131,44.04808449999999
42.2214597,43.9644051
42.1940309,43.7733115
42.3893816,43.9248521
42.12432640000001,44.4846623
42.2710657,44.0677554
42.3842131,44.04808449999999
42.2214597,43.9644051
-25.7698511,28.2599714
-33.9248685,18.4240553
18.0556339,-76.7886459
35.6606595,139.741572
37.9267863,139.0603306
34.8089824,135.4739092
43.0402172,141.3417678'''
finder = timezonefinder.TimezoneFinder()
timezoneolson_target = 'Europe/Paris'
timestamp = datetime.datetime(2024, 3, 17, 20, 0, 0)
strftime = '%Y-%m-%d %H:%M:%S'
for line in latlnglist.strip().splitlines():
lat, lng = map(float, line.split(','))
timezoneolson_local = finder.timezone_at(lat=lat, lng=lng)
#print(timezoneolson_local)
ts = pytz.timezone(timezoneolson_local).localize(timestamp).astimezone(pytz.timezone(timezoneolson_target)).strftime(strftime)
print(ts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment