Author Topic: Extended (Unix Epoch) Timer by SMcNeill  (Read 8674 times)

0 Members and 1 Guest are viewing this topic.

Offline The Librarian

  • Moderator
  • Newbie
  • Posts: 39
    • View Profile
Extended (Unix Epoch) Timer by SMcNeill
« on: August 11, 2019, 05:29:22 am »
Extended (Unix Epoch) Timer

Contributor(s): @SMcNeill
Source: qb64 @ Freeforums
URL: http://qb64.freeforums.net/thread/20/extended-timer-uet
Tags: [date], [time], [timer]

Description:
The Unix Epoch Time is a popular timekeeping standard based on the number of seconds elapsed since midnight on Jan 1, 1970 in Greenwich, London. The Extended Timer function below will calculate the (relative) Unix epoch time from the local system time and date.

Source Code:
Code: QB64: [Select]
  1. SHELL "https://www.epochconverter.com/"
  2.     CLS
  3.     PRINT TIMER, INT(ExtendedTimer)
  4.     PRINT "Compare to the time at https://www.epochconverter.com/"
  5.     _DISPLAY
  6.     _LIMIT 10
  7.  
  8. FUNCTION ExtendedTimer##
  9.     d$ = DATE$
  10.     l = INSTR(d$, "-")
  11.     l1 = INSTR(l + 1, d$, "-")
  12.     m = VAL(LEFT$(d$, l))
  13.     d = VAL(MID$(d$, l + 1))
  14.     y = VAL(MID$(d$, l1 + 1)) - 1970
  15.     FOR i = 1 TO m
  16.         SELECT CASE i 'Add the number of days for each previous month passed
  17.             CASE 1: d = d 'January doestn't have any carry over days.
  18.             CASE 2, 4, 6, 8, 9, 11: d = d + 31
  19.             CASE 3: d = d + 28
  20.             CASE 5, 7, 10, 12: d = d + 30
  21.         END SELECT
  22.     NEXT
  23.     FOR i = 1 TO y
  24.         d = d + 365
  25.     NEXT
  26.     FOR i = 2 TO y STEP 4
  27.         IF m > 2 THEN d = d + 1 'add an extra day for leap year every 4 years, starting in 1970
  28.     NEXT
  29.     d = d - 1 'for year 2000
  30.     s~&& = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
  31.     ExtendedTimer## = (s~&& + TIMER)
  32.  

screenshot.png
* Extended Timer.bas (Filesize: 1.04 KB, Downloads: 617)
« Last Edit: March 07, 2020, 01:21:44 am by The Librarian »