Delphi and date Interchange in Java

Source: Internet
Author: User

In a recent project, Java and Delphi were used to find that they could not read the date type correctly, such as writing a date value of "2007-12-1" in Java, which is not the value of Delphi reading.
By looking at the data, it was found that the definitions for date types were slightly different. The date in Java is stored using a long integer, which represents the number of milliseconds from "1970-1-1". For example, "1970-1-2" is 86400000 milliseconds after "1970-1-1", so 86400000 is used in Java to represent the "1970-1-2" date. Since the long integer is signed, we can use a negative number of milliseconds to represent the date before "1970-1-1". The dates in Delphi are stored using a double type, the integer part represents the number of days from "1899-12-30", and the fractional part represents the hour. The value "2.75" means "1900-1-1 6:00pm" and "1.25" means "1899-12-29".
Because the date type differs from the start date, the same "0" value represents a different date in both. Then a conversion is needed to communicate the date value between Java and Delphi.

//Convert a date in Java to a date in DelphifunctionConvertjavadatetimetodelphidatetime (Value:int64): Tdatetime;beginResult:= Incmillisecond (Strtodate ('1970-1-1'), Value);End;//Convert a date in Delphi to a date in JavafunctionConvertdelphidatetimetojavadatetime (adatetime:tdatetime): Extended;beginResult:= Millisecondspan (Adatetime, Strtodate ('1970-1-1'))End;

Reference: http://blog.csdn.net/chris_mao/article/details/1921864

Delphi and date Interchange in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.