Hello,
I need to send a Java date (milliseconds since the epoch 1970-01-01
00:00:00.000 GMT) through a socket to a C++ app and reconstruct exactly the
same date in the C++ app as in the Java app.
The date (actually the milliseconds since the epoch) is splitted in 8 bytes
and sent through the socket.
How can I recalculate the date in c++? Are there methods / classes for this
purpose in c++? And if not: how is the amount of milliseconds in Java
precisely calculated?
greetings,
Mike 17 6129
On Tue, 18 Oct 2005 01:14:41 +0200, <Mike> wrote or quoted : How can I recalculate the date in c++?
There is nothing to calculate. The only problem you might have is
endianness. To write a little-endian long see nio or http://mindprod.com/products1.html#LEDATASTREAM
Perhaps your problem is reconstructing a long from 8 bytes in C?
Look at how LeDataInputStre am does it in Java. The C code would be
very similar.
--
Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts.
Mike wrote: I need to send a Java date (milliseconds since the epoch 1970-01-01 00:00:00.000 GMT) through a socket to a C++ app and reconstruct exactly the same date in the C++ app as in the Java app.
The date (actually the milliseconds since the epoch) is splitted in 8 bytes and sent through the socket.
How can I recalculate the date in c++? Are there methods / classes for this purpose in c++?
Not in the Standard C++. But if leap seconds are not very important,
you should simply assume 1000 ms per sec, 60 sec per min, 60 mins per
hr, 24 hrs per day, 365 (or 366) days per year, I recon. Once you
have the GMT date, you can use 'mktime' and 'localtime' functions to
reconstruct the local time.
And if not: how is the amount of milliseconds in Java precisely calculated?
Shouldn't you ask this in a Java newsgroup?
V
Roedy Green wrote: On Tue, 18 Oct 2005 01:14:41 +0200, <Mike> wrote or quoted :
How can I recalculate the date in c++? There is nothing to calculate. The only problem you might have is endianness. To write a little-endian long see nio or http://mindprod.com/products1.html#LEDATASTREAM
Perhaps your problem is reconstructing a long from 8 bytes in C?
(a) It's C++.
(b) 'long' is often only 4 bytes, it would be impossible to reconstruct
it in that case, don't you think?
Look at how LeDataInputStre am does it in Java. The C code would be very similar.
It's C++.
V
Victor Bazarov wrote: Not in the Standard C++. But if leap seconds are not very important, you should simply assume 1000 ms per sec, 60 sec per min, 60 mins per hr, 24 hrs per day, 365 (or 366) days per year, I recon. Once you have the GMT date, you can use 'mktime' and 'localtime' functions to reconstruct the local time.
What's wrong with using some form of multi-precision integer class,
dividing by 1000, checking for overflow, and using the result as a
time_t? localtime() and gmtime() use secnods since epoch UTC.
"red floyd" <no*****@here.d ude> wrote in message
news:7u******** *********@newss vr25.news.prodi gy.net... Victor Bazarov wrote:
Not in the Standard C++. But if leap seconds are not very important, you should simply assume 1000 ms per sec, 60 sec per min, 60 mins per hr, 24 hrs per day, 365 (or 366) days per year, I recon. Once you have the GMT date, you can use 'mktime' and 'localtime' functions to reconstruct the local time.
What's wrong with using some form of multi-precision integer class, dividing by 1000, checking for overflow, and using the result as a time_t? localtime() and gmtime() use secnods since epoch UTC.
I don't believe there's any requirement that 'time_t'
be an integer type, or that there is a conversion from
an integer type to a 'time_t'.
-Mike
Mike Wahler wrote: "red floyd" <no*****@here.d ude> wrote in message news:7u******** *********@newss vr25.news.prodi gy.net... Victor Bazarov wrote:
Not in the Standard C++. But if leap seconds are not very important, you should simply assume 1000 ms per sec, 60 sec per min, 60 mins per hr, 24 hrs per day, 365 (or 366) days per year, I recon. Once you have the GMT date, you can use 'mktime' and 'localtime' functions to reconstruct the local time.
What's wrong with using some form of multi-precision integer class, dividing by 1000, checking for overflow, and using the result as a time_t? localtime() and gmtime() use secnods since epoch UTC.
I don't believe there's any requirement that 'time_t' be an integer type, or that there is a conversion from an integer type to a 'time_t'.
That's true. There is no requirement that 'time_t' is in any way
related to January 1st, 1970, either.
V
<Mike> wrote in message news:43******** *************** @news.xs4all.nl ... Hello,
I need to send a Java date (milliseconds since the epoch 1970-01-01 00:00:00.000 GMT) through a socket to a C++ app and reconstruct exactly the same date in the C++ app as in the Java app.
The date (actually the milliseconds since the epoch) is splitted in 8 bytes and sent through the socket.
Is date big endian or little endian?signed or unsigned?
Is it send as two consecutive 4 byte integers or single one?
Do you use any standard api CDR/XDR for example? How can I recalculate the date in c++? Are there methods / classes for this purpose in c++?
If you know the details calculation is not a problem :)
Greetings, Bane.
No need for big calculations.
There are standard C functions that deal with it.
Take a look at: http://www.delorie.com/gnu/docs/glibc/libc_435.html
You have to be careful with OS specifics:
1- Endianness: be sure that the 8 bytes from java (allways big endian)
will be
assign correctly in the c++ part.
2- The standard C functions use time_t, which is typically define as a
long (you must verify it in time.h -> sys/types.h) which is typically
32bits (depending on systems) which 4 bytes and NOT 8 bytes.
3- java.util.Date. getTime() returns a long which is the number of
milliseconds since the epoch.
On the other hand, the standard C functions use time_t which represents
the number of seconds since the epoch.
Epochs are the same in both cases.
Good luck!
<Mike> wrote: Hello,
I need to send a Java date (milliseconds since the epoch 1970-01-01 00:00:00.000 GMT) through a socket to a C++ app and reconstruct exactly the same date in the C++ app as in the Java app.
The date (actually the milliseconds since the epoch) is splitted in 8 bytes and sent through the socket.
How can I recalculate the date in c++? Are there methods / classes for this purpose in c++? And if not: how is the amount of milliseconds in Java precisely calculated?
greetings,
Mike
Use the getTimeInMillis method of the Calendar class to get the UTC which is
a long int, then send that to the C++ program.
In C++ use localtime to convert to a tm struct to be able to mess with the
individual time components.
Cheers,
Pep. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Hong |
last post by:
Help please, I try to sending an email from my html page using the java
applet.
but it give error on most of the PC only very few work, what is the error i
make
the java applet show as below
**********************************
package Celcom.Client;
|
by: Michael |
last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP,
I am unable to find out why the "Build for Debug" option within Stored
Procedure Builder is not enabled on Java stored procedures. It is enabled
for SQL stored procedures.
It is possible to "Build" and "Run" the Java SPs, it just isn't possible to
click on the "Build for Debug" option. Thanks for any help in advance.
Michael
|
by: LandWolf |
last post by:
Hi,
I have a Web services write in Java and I want to write a client in C#.
My web services work with Weather prevision. Hence, I set a date and my
web services return the prevision for that date. When the web service
return the date, this date is wrong.
Es:
Choose date: 24-apr-2006
Responce of Web service: day: 23-apr-2006, condition: sunny,
temperature: 28
|
by: rohayre |
last post by:
Im a long time java developer and actually have never done anything
with java scripting. I'd like to write a short simple script for
calculating a date in the future based on today's date and a letter.
Can I use javascripting to create a webpage to allow a user to enter a
letter and then click a button to find a future calendar date? I'm just
not sure how much user interaction scripting allows. Does java
scripting allow buttons, textfields...
|
by: TraceyAnnison |
last post by:
I wonder if you can help me - I'm new to this, and working in a project that has already been configured to work with Axis.
We have a Java project built with the Spring framework, in order to provide webservices for access via SOAP. As I understand it (ie not very well!) Axis works to accept these SOAP messages from the client and transform them into calls on our Java methods, and do the reverse with the responses - cool! Which is excellent,...
| |
by: helpwithcode |
last post by:
Hi people,
I am just learning java.I have been creating a project which involves JDBC Connectivity.I find that the statements,
String string_dob=text_dob.getText();
//Converting string to date
System.out.println(string_dob);
s.Info_DOB=Date.valueOf(string_dob);
runs perfectly fine in the method insert() and throws up an illegal Exception in the method UPDATE.This is the error I get when I pass a date "1979-05-02"
|
by: Nick048 |
last post by:
Hi to All,
In order to create a Date Picker that I need to use in Oracle forms, I have modified some element in the source of original calendarPJC provided from Oracle.
Following the instruction I have compiled in the correct order the Java file.
The first is CalendarWidgetEvent.java with this code:
package oracle.forms.demos;
|
by: Joshepmichel |
last post by:
Please to help me to following problem
I want to do this
1. create Table Name MEMBER on the Database Name "mytestdb",
2. Add the Values to the Table through the Key board Inputs during running the My Java Application.; Therefore I used this following codes, It Consists the seperate parts for the Raede and Member Class for the purposely I craetes.
3. I have problem to Parsing the values to SQL statement, that Consists on the Run Time...
|
by: robtyketto |
last post by:
Greetings,
I have the following code below which allows the date to be added via a JDBC connection as a STRING.
The value of dateString is inserted into the MS ACCESS database.
What is the easiest method to add the current date/time (dd/mm/yy hh:mm:ss) via JDBC in DATE format i.e. convert STRING to DATE or format the DATE without changing its type and insert it.
I'm a newbie to Java/Jsp too.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |