[DGD] Current Time

Mikael Lind z94lind at mtek.chalmers.se
Tue Dec 18 14:59:27 CET 2001


Quoting Chooser Fireman from 21:59, 2001-12-17:

> Wondering if there was a way to get the current time?
>
> And if there is, is it possible to say add 6 weeks to it or something?

Example code:

void display(string message) {
    /* echo the message to a user, for instance */
    /* ... */
}

void display_time() {
    /*
     * timestamps for present and future use ;D
     *
     * a timestamp is a count of seconds elapsed since 1970-01-01,
     * 00:00:00, a.k.a. the Epoch
     */
    int present, future;

    present = time(); /* get the current time */
    future = present + (6 * 7 * 24 * 60 * 60); /* add six weeks */
    display("The present: " + ctime(present));
    display("The future: " + ctime(future));

    display("I will notify you when the present becomes the future.");
    call_out("display_future", future - present);
}

void display_future() {
    display("The future is here.");
}

So, time() fetches you a timestamp for the present, while ctime()
formats a timestamp into a description.

dgd/doc/kfun/time
dgd/doc/kfun/ctime

If you need higher resolution than seconds, there is also
millitime().

dgd/doc/kfun/millitime

// Mikael / Elemel

--
I embrace my desire to feel the rhythm / To feel connected enough to
step aside and weep like a widow / To feel inspired / To fathom the
power / To witness the beauty / To bathe in the fountain / To swing
on the spiral of our divinity and still be a human // Tool

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list