![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 10 of 13 total |
![]() |
Tue, Jul 19 2016 2:21 PM | Permanent Link |
thomh | Hi,
Is there an easy way to convert DateTime in EWB to Delphi TDateTime and back again? Thanks. // Thom |
Tue, Jul 19 2016 3:20 PM | Permanent Link |
Walter Matte Tactical Business Corporation | Routines I use.....
function UNIXTimeToDateTimeFAST(UnixTime: Int64): TDateTime; const MsecPerDay : int64 = 86400000; DayDiff : int64 = 25569; var DT : TDateTime; begin DT := (UnixTime / MsecPerDay) + DayDiff; result := DT; // swap // result := UTCToLocal(DT); // 1.02 Comment Out WBM end; function DateTimeToUNIXTimeFAST(DelphiTime : TDateTime): Int64; const MsecPerDay : int64 = 86400000; DayDiff : int64 = 25569; var DT : TDateTime; X : extended; begin // DT := LocalToUTC(DelphiTime); // 1.02 Comment Out WBM DT := DelphiTime; // swap x := (DT - DayDiff) * MsecPerDay; result := round(X); end; function UNIXTimeToTimeFAST(UnixTime: Int64): TDateTime; const MsecPerDay : int64 = 86400000; DayDiff : int64 = 25569; var DT : TDateTime; begin DT := (UnixTime / MsecPerDay); result := DT; // swap // result := UTCToLocal(DT); // 1.02 Comment Out WBM end; function TimeToUNIXTimeFAST(DelphiTime : TDateTime): Int64; const MsecPerDay : int64 = 86400000; DayDiff : int64 = 25569; var DT : TDateTime; X : extended; begin // DT := LocalToUTC(DelphiTime); // 1.02 Comment Out WBM DT := DelphiTime; // swap x := (DT - Trunc(DT)) * MsecPerDay; result := round(X); end; |
Tue, Jul 19 2016 4:11 PM | Permanent Link |
thomh | Thanks, Walter.
There is something funky going on though. I have a little class which contains a DateTime property. I set this property to today's date using User.DateOfBirth = Date. I use TWriter to write a JSON string of this class and User.DateOfBirth gets converted to 1468879200000. If I pass this value to your UNIXTimeToDateTime I get the date 2016.07.18 which was yesterday. // Thom |
Tue, Jul 19 2016 4:22 PM | Permanent Link |
thomh | That's weird.
When I code it in Delphi: LDate := Date; LDateInt := DateTimeToUNIXTime(LDate); returns 1468886400000 compared to 1468879200000 in EWB. And LDate := UNIXTimeToDateTime(LDateInt) does return the correct date (2016.07.19) So EWB seems to subtract one day when writing to a DateTime to JSON. // Thom |
Tue, Jul 19 2016 4:26 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | Thom,
<< So EWB seems to subtract one day when writing to a DateTime to JSON. >> Where is the date originating from ? You have to remember to localize DateTime values, if so desired. Tim Young Elevate Software www.elevatesoft.com |
Tue, Jul 19 2016 4:31 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | Thom,
Never mind, I see that you're using the Date() function. The part about localization is still correct, however. ![]() Also, if you're using the EWB Web Server with a web server module, you can use these methods: http://www.elevatesoft.com/manual?action=viewmethod&id=ewb2mod&product=rsdelphi&version=XE&comp=TEWBServerRequest&method=DateTimeToMSecs http://www.elevatesoft.com/manual?action=viewmethod&id=ewb2mod&product=rsdelphi&version=XE&comp=TEWBServerRequest&method=MSecsToDateTime http://www.elevatesoft.com/manual?action=viewmethod&id=ewb2mod&product=rsdelphi&version=XE&comp=TEWBServerRequest&method=GMTDateTimeToLocal http://www.elevatesoft.com/manual?action=viewmethod&id=ewb2mod&product=rsdelphi&version=XE&comp=TEWBServerRequest&method=LocalDateTimeToGMT Tim Young Elevate Software www.elevatesoft.com |
Tue, Jul 19 2016 4:40 PM | Permanent Link |
thomh | Hi Tim,
What do you mean "localize DateTime values" ? // Thom |
Tue, Jul 19 2016 5:29 PM | Permanent Link |
thomh | And I am using RemObjects and not the EWB Web Server.
// Thom |
Tue, Jul 19 2016 5:37 PM | Permanent Link |
thomh | And since I using TWriter to convert Date() to JSON, the problem seems to be here:
procedure TWriter.DateTimeValue(Value: DateTime); begin case FDateTimeFormat of dtfISO8601: Append(QuotedStr(DateTimeToISOStr(Value),DOUBLE_QUOTE)); else Append(IntToStr(Integer(Value))); end; end; // Thom |
Tue, Jul 19 2016 8:52 PM | Permanent Link |
erickengelke | >thomh wrote:
>And since I using TWriter to convert Date() to JSON, the problem seems to be here: > > Append(QuotedStr(DateTimeToISOStr(Value),DOUBLE_QUOTE)); The EWB time functions have an optional USEUTC parameter except DateTimeToISOStr() which I believe always converts to UTC time, which we old farts call Grenich mean time.. |
Page 1 of 2 | Next Page » | |
Jump to Page: 1 2 |
This web page was last updated on Thursday, March 30, 2023 at 10:19 AM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |