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

0 Members and 1 Guest are viewing this topic.

#### The Librarian

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

Contributor(s): @SMcNeill
Source: qb64 @ Freeforums
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.     PRINT TIMER, INT(ExtendedTimer)
3.     PRINT "Compare to the time at https://www.epochconverter.com/"
4.     _LIMIT 10
5.
6. FUNCTION ExtendedTimer##
7.     d\$ = DATE\$
8.     l = INSTR(d\$, "-")
9.     l1 = INSTR(l + 1, d\$, "-")
10.     m = VAL(LEFT\$(d\$, l))
11.     d = VAL(MID\$(d\$, l + 1))
12.     y = VAL(MID\$(d\$, l1 + 1)) - 1970
13.     FOR i = 1 TO m
14.         SELECT CASE i 'Add the number of days for each previous month passed
15.             CASE 1: d = d 'January doestn't have any carry over days.
16.             CASE 2, 4, 6, 8, 9, 11: d = d + 31
17.             CASE 3: d = d + 28
18.             CASE 5, 7, 10, 12: d = d + 30
19.     FOR i = 1 TO y
20.         d = d + 365
21.     FOR i = 2 TO y STEP 4
22.         IF m > 2 THEN d = d + 1 'add an extra day for leap year every 4 years, starting in 1970
23.     d = d - 1 'for year 2000
24.     s~&& = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
25.     ExtendedTimer## = (s~&& + TIMER)
26. « Last Edit: March 07, 2020, 01:21:44 am by The Librarian »