> I've just ran into a brick wall.
>
> Where is the epoc time support in Rebol?
>

It's easy enough to do, Deryk... Here's to epoch time:

----------------------------------------------------------------------

 REBOL[
        File: %epoch.r
        Author: "Ralph Roberts"
 ]


date: now

seconds: ((date - 1-1-1970) * 86400) + (date/time/hour * 3600) +
(date/time/minute * 60) + date/time/second

zone: now/zone

zone: zone/hour

zone: zone * 3600

seconds: seconds - zone         ; minus a minus gives plus

print seconds
----------------------------------------------------------------

(I just ran the above and got 960987050 for the time period that I'm doing
this message).

And here's how to convert back:

------------------------------------------------------------------

REBOL [
        Title: "Convert Epoch Time to Date"
        Author: "Ralph Roberts"
        File: %epoch-to-date.r
        Date: 21-Feb-2000
        Purpose: {converts UNIX Epoch time (seconds after 1-1-1970)
                        to current date and time }
        Example: {outputs "Epoch date 951142987 is 21-Feb-2000
                14:38:52 GMT or 9:38:52 Local" }
        ]

        epoch: 951505087

        days: divide epoch 86400

        days2: make integer! days

        time: (days - days2) * 24
        hours: make integer! time
        minutes: (time - hours) * 60
        minutes2: make integer! minutes
        seconds: make integer! (minutes - minutes2) * 60
        time2: make time! ((((hours * 60) + minutes2) * 60) + seconds)

prin ["Epoch date" epoch "is" 1-Jan-1970 + days2 time2]
print [" GMT or" time2 + now/zone "Local"]
-----------------------------------------------------------------


Enjoy!

--Ralph Roberts

author: REBOL/CORE FOR DUMMIES


Reply via email to