[fpc-pascal] convert "epoch" to UTC

Sven Barth pascaldragon at googlemail.com
Mon Jan 16 18:40:29 CET 2012


On 16.01.2012 17:57, waldo kitty wrote:
>> 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 ).
>
> i think i might be able to do something with the JulianToDateTime once i
> get the base year portion converted to a true julian... i spotted some
> C# code while doing a bit of research earlier (see below)... it appears
> to convert the year to a julian year and then add the decimal day
> portion... this should then be a proper julian date which i should be
> able to handle ;)
>
> [---- WARNING: C# code follows ----]
> double getJulianDay_Year(int year)
> {
> double dYear = year - 1;
> double A = Math.Floor(dYear / 100);
> double B = 2 - A + Math.Floor(A / 4);
> //The use of 30.600000000000001 is to correct for floating point
> rounding problems
> double dResult = Math.Floor(365.25 * dYear) + 1721422.9 + B;
> return dResult;
> }
>
> double getJulianDay_SatEpoch(int year, double dSatelliteEpoch)
> {
> //Tidy up the year and put it into the correct century
> year = year % 100;
> if (year < 57) year += 2000;
> else year += 1900;
>
> double dResult = getJulianDay_Year(year);
> dResult += dSatelliteEpoch;
>
> return dResult;
> }
> [---- end of C# code ----]
>
> looks like it should be easy to convert to pascal, too ;) just gotta
> find out what that "floor" routine does ;)

Well... I would say the same as FPC's "floor" routine ( 
http://www.freepascal.org/docs-html/rtl/math/floor.html ) does ;)

A hint for converting C# code: it might help to google for (in this 
case) "Math.Floor .net" which will often result in a MSDN link like this 
one: http://msdn.microsoft.com/en-us/library/e0b5f0xb.aspx

Regards,
Sven



More information about the fpc-pascal mailing list