[fpc-pascal] Timezone information in a dataset datetime field? - updated
Reinier Olislagers
reinierolislagers at gmail.com
Sat Jul 23 18:41:12 CEST 2011
Hi all,
I'm busy with writing an XML export unit targeting Microsoft Access/.Net
framework (ADO.NET data access framework in particular).
Runing an ADO.NET demo program I found out that the ADO.NET variant
requires timezone info in its date/time fields.
In a sample export I did, it is set to my timezone (UTC+2 at this moment).
1. Is there any way of knowing what kind of timezone a datetime value
should be in a FPC dataset? (I suppose not...)
2. If not, I think I'm going to just use the current timezone. Is there
any cross-platform way of doing this? In the docs, I just found
GetLocalTimezone/TZSeconds in e.g. the linux unit... I could of course
use the Windows API to get something similar on Windows, but what about
OSX, or BSD or Solaris...
I found some code thread How to get UTC time from 2007:
would that still be the best solution?
2a: Unix:
{$mode Delphi}
uses unix,sysutils,baseunix;
function utc_now : TDateTime;
var
timeval: TTimeVal;
timezone: PTimeZone;
a: Double;
begin
TimeZone := nil;
fpGetTimeOfDay (@TimeVal, TimeZone);
// Convert to milliseconds
a := (TimeVal.tv_sec * 1000.0) + (TimeVal.tv_usec / 1000.0);
Result := (a / MSecsPerDay) + UnixDateDelta;
end;
2b: Windows:
{$ifdef MSWINDOWS}
{ This uses SysUtils and Windows. }
function emt_now: TDateTime;
var
st: TSystemTime;
begin
GetSystemTime (st);
Result := SystemTimeToDateTime (st);
end;
{$endif}
Thanks,
Reinier
More information about the fpc-pascal
mailing list