[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: different date/time representations
From: |
Mike Miller |
Subject: |
Re: different date/time representations |
Date: |
Thu, 26 May 2016 09:33:49 -0700 |
User-agent: |
Mutt/1.6.0 (2016-04-01) |
On Thu, May 26, 2016 at 12:17:33 +0200, Andreas Weber wrote:
> Dear all,
>
> Since I'm always baffled because the different representations for
> date/time in GNU Octave (serial day number, date vector, time structure
> and so on) I made a graphic to help me when dealing with date/time:
>
> http://www.tech-chat.de/images/GNU_Octave_date_time.svg
Nice chart! Could use some color :)
> Am I missing something? Should I add this to the wiki?
>
> And is there a direct way from "seconds since the epoch" to "serial day
> number"?
> A function like:
>
> tm = localtime (t);
> ret = datenum (tm.year + 1900, tm.mon + 1, tm.mday, tm.hour, tm.min,
> tm.sec + tm.usec / 1e6)
Sure, this conversion works for me directly from a time_t:
utc_offset = -7;
num = time () / 86400 + utc_offset / 24 + 719529;
You could also use the gmtoff field:
t = time ();
num = (t + localtime (t).gmtoff) / 86400 + 719529;
I found 719529 empirically from
datenum (1970, 1, 1, 0, 0, 0)
presumably the number of days from 0000-01-01 to 1970-01-01.
--
mike
signature.asc
Description: PGP signature