Java约会C ++ [英] Java date to C++

查看:64
本文介绍了Java约会C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我需要发送一个Java日期(自1970-01-01纪元以来的几毫秒
$ b $ 00 00:00:00.000 GMT) C ++应用程序的套接字,并在C ++应用程序中完全重建与Java应用程序相同的日期。


日期(实际上是自以后的毫秒数) epoch)分为8个字节

并通过套接字发送。


如何用c ++重新计算日期?在c ++中是否存在用于此

目的的方法/类?如果没有:Java中的毫秒数如何精确计算出来?


问候,


迈克

解决方案

2005年10月18日星期二01:14:41 +0200,< Mike>写道或引用:

如何用c ++重新计算日期?



没有什么可以计算的。你可能遇到的唯一问题是

endianness。要写一个小端,请看nio或
http:// mindprod。 com / products1.html #LEDATASTREAM


也许你的问题是从C中的8个字节重建一个长的?

看看LeDataInputStream是如何做到的在Java中。 C代码将是非常相似的




-

加拿大心灵产品,Roedy Green。
< a rel =nofollowhref =http://mindprod.comtarget =_ blank> http://mindprod.com 再次获取新的Java编程合同。


Mike写道:

我需要通过套接字发送一个Java日期(自格陵兰1970-01-01
00:00:00.000 GMT以来的毫秒) C ++应用程序并在C ++应用程序中重建与Java应用程序完全相同的日期。

日期(实际上是自纪元以来的毫秒数)被分成8个字节和通过套接字发送。

如何用c ++重新计算日期?在c ++中是否有用于此目的的方法/类?


不在标准C ++中。但如果闰秒不是很重要,那么你应该假设每秒1000毫秒,每分钟60秒,每分钟60分钟,每天24小时,365天(或366)每年,我侦察。一旦你有
有GMT日期,你可以使用''mktime''和''localtime''函数来

重建当地时间。

如果没有:如何精确计算Java中的
毫秒量?




难道你不能在Java新闻组中问这个吗? br />

V


Roedy Green写道:

2005年10月18日星期二01:14:41 +0200,< Mike>写道或引用:

如何在c ++中重新计算日期?没有什么可以计算的。您可能遇到的唯一问题是
endianness。要写一个小端,请看nio或
http:// mindprod。 com / products1.html #LEDATASTREAM

也许你的问题是从C中的8个字节重建长?




(a )它是C ++。

(b)''long''通常只有4个字节,在这种情况下不可能重建

,不要你觉得呢?

看看LeDataInputStream是如何在Java中完成它的。 C代码非常相似。



它是C ++。


V


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

解决方案

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 LeDataInputStream 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 LeDataInputStream does it in Java. The C code would be
very similar.


It''s C++.

V


这篇关于Java约会C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆