Thread View: borland.public.delphi.rtl
7 messages
7 total messages
Started by Manuel V�zquez Acosta
Tue, 06 Jan 2004 20:58
DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Manuel V�zquez Acosta
Date: Tue, 06 Jan 2004 20:58
Date: Tue, 06 Jan 2004 20:58
17 lines
1657 bytes
1657 bytes
Hi all: I've been facing a little problem usign DateTime conversion functions to (and from) Unix: DateTimeToUnix and UnixToDateTime. I've developed a PHP WebService which sends a unix timestamp to the client (a delphi one). In Delphi I coded something like this: timeStr := DateTimeToStr(UnixToTimeDate(unixTimeFromWS)); Although the WS and the Delphi client are running on the same box (i.e. same localization settings, UTC, etc); the variable timeStr gets the wrong string. Any hints? Manuel.
Re: DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Mike Williams (TeamB)
Date: Tue, 06 Jan 2004 20:20
Date: Tue, 06 Jan 2004 20:20
9 lines
1347 bytes
1347 bytes
On 06 Jan 2004, "Manuel V�zquez Acosta" <mva_led@yahoo.com> wrote: > Although the WS and the Delphi client are running on the same box > (i.e. same localization settings, UTC, etc); the variable timeStr gets > the wrong string. How wrong is it? Can you post some examples of the various values? -Mike (TeamB)
Re: DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Mike Williams (TeamB)
Date: Wed, 07 Jan 2004 13:14
Date: Wed, 07 Jan 2004 13:14
9 lines
1286 bytes
1286 bytes
On 07 Jan 2004, "Manuel V�zquez Acosta" <mva_led@yahoo.com> wrote: > As you can see the date matches but the time doesn't. Right. It's exactly 5 hours off because of your timezone which is not part of the unix date/time. I the unix date/time uses GMT/UTC or something similar. -Mike (TeamB)
Re: DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Manuel V�zquez Acosta
Date: Wed, 07 Jan 2004 14:02
Date: Wed, 07 Jan 2004 14:02
41 lines
2101 bytes
2101 bytes
I have made a simple test: A delphi program which main code is following:
procedure TForm1.Button1Click(Sender: TObject);
var
vTime : TDateTime;
unixTime : Cardinal;
begin
vTime := Now();
unixTime := DateTimeToUnix(vTime);
Edit1.Text := IntToStr(unixTime);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
unixTime : Cardinal;
begin
unixTime := StrToInt(Edit1.Text);
Memo1.Lines.Add(DateTimeToStr(UnixToDateTime(unixTime)));
end;
Pressing Button1 I got 1073465414, and then pressing Button2 I got the
string: 1/7/2004 8:50:14 AM;
Although, the PHP program:
<?php
$s = 1073465414; // Notice this is the unix timestamp Delphi gave
me
echo $s;
echo "<br>";
echo date('j/n/y \a \l\a\s g:i a', $s);
?>
Prints:
1073465414
7/1/04 a las 3:50 am
As you can see the date matches but the time doesn't.
Hoping this helps,
Manuel.
Re: DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Manuel V�zquez Acosta
Date: Wed, 07 Jan 2004 16:08
Date: Wed, 07 Jan 2004 16:08
18 lines
1803 bytes
1803 bytes
Thanks, normalizing the PHP code to -5 GMT worked! Can I tell to Delphi to use 0 GMT, and not my local timezone? Manuel. "Mike Williams (TeamB)" <mikew@remove.aps-soft.com> wrote in message news:Xns94695DEE2D233mikewteamb@207.105.83.66... > On 07 Jan 2004, "Manuel V�zquez Acosta" <mva_led@yahoo.com> wrote: > > > As you can see the date matches but the time doesn't. > > Right. It's exactly 5 hours off because of your timezone which is not part > of the unix date/time. I the unix date/time uses GMT/UTC or something > similar. > > -Mike (TeamB)
Re: DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Mike Williams (TeamB)
Date: Wed, 07 Jan 2004 18:09
Date: Wed, 07 Jan 2004 18:09
12 lines
1609 bytes
1609 bytes
On 07 Jan 2004, "Manuel V�zquez Acosta" <mva_led@yahoo.com> wrote: > Can I tell to Delphi to use 0 GMT, and not my local timezone? I think it's a Windows vs Unix thing. You can easily write your own wrapper routine that gets the local timezone and compensates for it but you still have to worry about daylight savings time, etc. I think you might want to do a little more research on the whole subject before throwing something together. There's certainly information and probably code out there that will help you out. -Mike (TeamB)
Re: DateTimeToUnix/DateTimeToStr interoperatibility problem with PHP
Author: Manuel V�zquez Acosta
Date: Wed, 07 Jan 2004 20:50
Date: Wed, 07 Jan 2004 20:50
39 lines
2776 bytes
2776 bytes
I wrote a custom Now function to use GetSystemTime instead of GetLocalTime,
and then the return unix timestamp was correctly interpreted by PHP.
I forgot to mention that I'm running PHP over Windows, so it can't be, in
this case, a Windows - Unix problem.
function phpNow : TDateTime;
var
SystemTime: TSystemTime;
begin
GetSystemTime(SystemTime); // In SysUtils Borland uses GetLocalTime
with SystemTime do
Result := EncodeDate(wYear, wMonth, wDay) + EncodeTime(wHour, wMinute,
wSecond, wMilliseconds);
end;
So I think I can use UTC for interchange of timestamps, and then convert it
to the local timezone. In Windows this could acomplished simply calling
SystemTimeToTzSpecificLocalTime API function. In Linux the systemcall
localtime would help.
Manu.
"Mike Williams (TeamB)" <mikew@remove.aps-soft.com> wrote in message
news:Xns9469900B039D0mikewteamb@207.105.83.66...
> On 07 Jan 2004, "Manuel V�zquez Acosta" <mva_led@yahoo.com> wrote:
>
> > Can I tell to Delphi to use 0 GMT, and not my local timezone?
>
> I think it's a Windows vs Unix thing. You can easily write your own
> wrapper routine that gets the local timezone and compensates for it but
you
> still have to worry about daylight savings time, etc. I think you might
> want to do a little more research on the whole subject before throwing
> something together. There's certainly information and probably code out
> there that will help you out.
>
> -Mike (TeamB)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads