Author Topic: Time zone conversions  (Read 4280 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Time zone conversions
« on: September 16, 2020, 12:26:30 pm »
Timezone conversions

Are there any time functions in QB64 that will help me to determine the time in another time zone?

As an example, if it is 10:00 PM on September 16, 2020, calculate the current time and date in the UK.

NOTE: The tricky part here is that the number of hours difference between the 2 locations varies because they don't both enter and exit daylight saving time on the same dates.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Time zone conversions
« Reply #1 on: September 16, 2020, 12:54:34 pm »
Try a "time zone" search.

Also might be in @SpriggsySpriggs API apps.
« Last Edit: September 16, 2020, 12:55:39 pm by bplus »

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Time zone conversions
« Reply #2 on: September 16, 2020, 04:32:05 pm »
Timezone conversions
NOTE: The tricky part here is that the number of hours difference between the 2 locations varies because they don't both enter and exit daylight saving time on the same dates.

That's only one tricky part.

Time zones are quite unpredictable. In principle, they depend on longitude. In practice, the demarcations are quite jagged, subject to local policies in each country and sometimes even regions. For example, some states in the US do not use daylight saving time, while even adjacent states do. And, these policies change, over time.

I don't see any other way than to look it up, and to make sure you have up to date info.

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Time zone conversions
« Reply #3 on: September 17, 2020, 12:05:04 pm »
Obligatory Tom Scott video:

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Time zone conversions
« Reply #4 on: September 17, 2020, 12:39:17 pm »
Is this why I everything I read last night is marked "New" again here at this forum?


Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Time zone conversions
« Reply #5 on: September 17, 2020, 04:59:43 pm »
Some airports have a wall of clocks like this.  As noted above, a simple constant offset
from Greenwich isn't accurate.  Shucks. 

Code: QB64: [Select]
  1. _TITLE "World Clock"
  2. DEFINT A-Z
  3. DIM p$(30), t!(30), t$(30), x(1), y(1)
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5. black& = _RGB32(0, 0, 0)
  6. green& = _RGB32(0, 200, 0)
  7. white& = _RGB32(200, 200, 200)
  8. FOR i = 1 TO 30: READ p$(i), t!(i): NEXT i
  9.  
  10. begin:
  11. t$ = TIME$
  12. h = VAL(MID$(t$, 1, 2)) + 7 '                    GMT = local + 7
  13. m = VAL(MID$(t$, 4, 2))
  14. IF h > 24 THEN h = h - 24
  15. FOR i = 1 TO 30 '                                actual time for each place
  16.     th = h + INT(t!(i))
  17.     z! = ABS(t!(i)) - ABS(INT(t!(i)))
  18.     tm = m + z! * 60 * SGN(t!(i))
  19.     IF tm < 0 THEN tm = tm + 60: th = th - 1
  20.     IF tm > 59 THEN tm = tm - 60: th = th + 1
  21.     IF th < 0 THEN th = th + 24
  22.     IF th > 23 THEN th = th - 24
  23.     th$ = RIGHT$("0" + LTRIM$(STR$(th)), 2)
  24.     tm$ = RIGHT$("0" + LTRIM$(STR$(tm)), 2)
  25.     t$(i) = th$ + tm$
  26. sort:
  27. sorted = 1
  28. FOR i = 1 TO 29
  29.     s = 0
  30.     IF stype = 0 THEN '                          place
  31.         IF p$(i) > p$(i + 1) THEN s = 1
  32.     ELSE '                                       time of day
  33.         IF t$(i) > t$(i + 1) THEN s = 1
  34.     END IF
  35.     IF s THEN
  36.         SWAP p$(i), p$(i + 1) '                  place
  37.         SWAP t!(i), t!(i + 1) '                  zone
  38.         SWAP t$(i), t$(i + 1) '                  time
  39.         sorted = 0
  40.     END IF
  41. IF sorted = 0 THEN GOTO sort
  42. d = 33: p = 0 '                                  distance, place index
  43. FOR yc = 42 TO 402 STEP 90 '                     x center
  44.     FOR xc = 70 TO 570 STEP 100 '                y center
  45.         x1 = xc - d - 18: y1 = yc - d
  46.         x2 = xc + d + 18: y2 = yc + d + 18
  47.         LINE (x1, y1)-(x2, y2), black&, BF '     erase old
  48.         p = p + 1 '                              place index
  49.         _PRINTSTRING (xc - _PRINTWIDTH(p$(p)) \ 2, yc + d + 4), p$(p)
  50.         CIRCLE (xc, yc), d, green&
  51.         IF VAL(LEFT$(t$(p), 2)) < 12 THEN PAINT (xc, yc), green&, green& ' am/pm
  52.         FOR a = 0 TO 360 STEP 30 '               clock tick marks
  53.             x1 = xc + (d - 3) * COS(_D2R(a))
  54.             y1 = yc + (d - 3) * SIN(_D2R(a))
  55.             CIRCLE (x1, y1), 1, white& '         ticks
  56.         NEXT a
  57.         th = VAL(MID$(t$(p), 1, 2)) '            hour
  58.         tm = VAL(MID$(t$(p), 3, 2)) '            minute
  59.         r! = _D2R(tm * 6 - 90) '                 minute hand
  60.         x(0) = xc + (d - 8) * COS(r!)
  61.         y(0) = yc + (d - 8) * SIN(r!)
  62.         r! = _D2R((th + tm / 60) * 30 - 90) '    hour hand
  63.         x(1) = xc + (d - 16) * COS(r!)
  64.         y(1) = yc + (d - 16) * SIN(r!)
  65.         FOR zz = 0 TO 1 '                        draw hands
  66.             FOR zx = -1 TO 1
  67.                 FOR zy = -1 TO 1
  68.                     LINE (xc + zx, yc + zy)-(x(zz), y(zz)), white&
  69.                 NEXT zy
  70.             NEXT zx
  71.         NEXT zz
  72.     NEXT xc
  73. NEXT yc
  74. t$ = LEFT$(TIME$, 5)
  75. LINE (10, 470)-(630, 471), black&, BF '           erase seconds bar at bottom
  76.     x = VAL(RIGHT$(TIME$, 2)) * 10 + 20
  77.     LINE (10, 470)-(x, 471), green&, B '          seconds bar
  78.     i$ = INKEY$
  79.     IF i$ = CHR$(27) THEN SYSTEM '                Esc to quit
  80.     IF i$ = " " THEN stype = 1 - stype '          spacebar changes sort (time or place)
  81. LOOP UNTIL (t$ <> LEFT$(TIME$, 5)) OR (i$ > "")
  82. GOTO begin
  83.  
  84. DATA Amsterdam,1
  85. DATA Beijing,8
  86. DATA Berlin,1
  87. DATA Brasilia,-3
  88. DATA Cairo,2
  89. DATA Chicago,-6
  90. DATA Delhi,5.5
  91. DATA Denver,-7
  92. DATA Detroit,-5
  93. DATA Edmonton,-7
  94. DATA Gander,-3.5
  95. DATA Hawaii,-10
  96. DATA Hong Kong,8
  97. DATA Houston,-6
  98. DATA Istanbul,2
  99. DATA London,0
  100. DATA Los Angeles,-9
  101. DATA Madrid,1
  102. DATA Mexico City,-6
  103. DATA Moscow,3
  104. DATA New York,-5
  105. DATA Paris,1
  106. DATA Perth,8
  107. DATA Phoenix,-8
  108. DATA Rome,1
  109. DATA Seoul,9
  110. DATA Singapore,8
  111. DATA Sydney,10
  112. DATA Tehran,3.5
  113. DATA Tokyo,9
  114.  
  115.  
It works better if you plug it in.

Marked as best answer by hanness on September 19, 2020, 06:28:24 pm

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Time zone conversions
« Reply #6 on: September 17, 2020, 06:31:42 pm »
I don't remember if I have something in my API collection but here is a link to a post where I asked a similar question about conversion for time zones and got some help on that. I use it for programs that I make. It could be in my API collection in my NASA one. Anyways, here is the link:
https://www.qb64.org/forum/index.php?topic=2823.msg121099#msg121099
« Last Edit: September 18, 2020, 01:32:32 am by SpriggsySpriggs »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Time zone conversions
« Reply #7 on: September 17, 2020, 07:17:23 pm »
Ah must of been that I was remembering, thanks Spriggsy.

@Richard Frost nice little app!
« Last Edit: September 17, 2020, 07:18:58 pm by bplus »

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Time zone conversions
« Reply #8 on: September 19, 2020, 10:28:16 pm »
Thanks for the help!