[fpc-pascal] convert "epoch" to UTC

Sven Barth pascaldragon at googlemail.com
Mon Jan 16 12:22:30 CET 2012


Am 16.01.2012 04:10 schrieb "waldo kitty" <wkitty42 at windstream.net>:
>
>
> i'm needing to convert a "UTC epoch" date to a "standard time string"...
by that, i mean that i want to get something like "2011-01-13 22:24:04" out
of the "epoch" number 12013.9338171...
>
> the above "epoch" number is (supposedly) built like this...
>
> 12 == 2012
> 013 == 13th day of the year
> .9338171 * 24 == 22.4116104 hours
> .4114104 * 60 == 24.696624 minutes
>
> and here's where it breaks on me because
>
> .696624 * 60 == 41.79744 seconds and that doesn't match the above time
string showing 04 seconds... that time string was built from this "epoch"
number (by another program) and i assume that it followed this published
formula for this format (which is for satellite TLEs)...
>
> so, my question is this... is there an existing FPC routine that will
convert this (or a part of this) properly or do i need to play with
something to get it right? it is obvious that this is not a "unix epoch"...
i'm not sure how "normal" julian date epochs are represented...
>
> i've looked through the docs on freepascal.org but none of them show an
number with which to compare... there's no links pointing to a definition
or example of a julian date or unix date or any such...

I don't know whether your format is really a Julian or Unix time (for
Julian it looks too low), but can take a look at unit "DateUtils" of which
the documentation is here:
http://www.freepascal.org/docs-html/rtl/dateutils/index-5.html
Especially you can try JulianToDateTime and UnixToDateTime. Both return a
TDateTime which you can convert to a string using FormatDateTime (
http://www.freepascal.org/docs-html/rtl/sysutils/datetimetostring.html ) or
DateTimeToStr (
http://www.freepascal.org/docs-html/rtl/sysutils/datetimetostr.html).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120116/7c814c3a/attachment.html>


More information about the fpc-pascal mailing list