convert date to c# ticks in java [duplicate] - java

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C# DateTime.Ticks equivalent in Java
hello guys
can anybody tell me how to convert date to .Net ticks in java.
any help will be appreciative.
thanks

ticks = 621355968000000000L+javaMillis*10000;

You may also want to check the icu4j library from the ICU project especially the UniversalTimeScale class which is similar to .Net ticks.

DateTime.Ticks Property The value of this property is the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001.
Date.getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
Accounting for the 1970 years offset and multiplying by ten seems to be the solution.

Related

Offset not calculated correctly at OffsetDateTime to Instant conversion in Java 8 [duplicate]

This question already has answers here:
ZonedDateTime America/Phoenix zone to GMT having issue [duplicate]
(3 answers)
Java Date Time conversion to given timezone
(3 answers)
Closed 7 months ago.
I would need the community's help because I could not find the answer in the Java documentation. I don't understand how the offset is taken into the math calculations when I try to convert an OffsetDateTime (ex: 2022-07-09T11:30:34) object to an Instant object. For example:
If we would run on OpenJDK 1.8 the command in a main function: OffsetDateTime.parse("2022-07-09T12:30:34+01:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME).toInstant() the outcome would be an Instance of date-and-time 2022-07-09T11:30:34 when I would had expected an Instant of 2022-07-09T13:30:34. The difference is the hour. Why do I get it like this?
And the opposite using -01:00 will do the revet.
I apologize for not formatting my text correctly or if I missed something. I would appreciate it if my post would not be marked us not worthy. And sorry if the answer was already answered in a different thread, which I could not find.
Thank you in advance.

Is save to use System.currentTimeMillis() after 2038? [duplicate]

This question already has answers here:
When will System.currentTimeMillis() overflow?
(6 answers)
Closed 3 years ago.
The Year 2038 problem (also called Y2038 or Unix Y2K) relates to representing time in many digital systems as the number of seconds passed since 00:00:00 UTC on 1 January 1970 and storing it as a signed 32-bit integer. Such implementations cannot encode times after 03:14:07 UTC on 19 January 2038. Just like the Y2K problem, the Year 2038 problem is caused by insufficient capacity of the chosen data type.
(source Wikipedia)
I tried to search how this affect Android and its applications. But I didnĀ“t find any clear answer about this. Therefore I would like to ask here:
Can we expect any problems in future (in 2038 and later), if our programs will use System.currentTimeMillis() method?
Are they any dangerous method we should avoid?
System.currentTimeMillis() returns a long, a 64 bit integer, so you'll be safe until the year 292278994.
Luckily, we'll all be dead by then.

Is there any way to add float number to millisecond in java Calendar? [duplicate]

This question already has answers here:
Any new method to get current time with accuracy in microseconds in Java now?
(3 answers)
Closed 6 years ago.
In java Calendar class while adding milliseconds I am missing the decimal precession. Since method expects integer
For example:
1000/12 = 83.333333
In java
Calendar c = Calendar.getInstance();
c.add(Calendar.MILLISECOND, (integer));
Which takes only 83 and .33333 is missed.
Does anybody know how to handle this scenario in java ?
java.util.Calendar keeps time information at the level of milliseconds,
An instant in time can be represented by a millisecond value that is an offset from the Epoch, January 1, 1970 00:00:00.000 GMT (Gregorian).
java.time.LocalDateTime has a sensitivity in the level of nanosecond.
Time is represented to nanosecond precision. For example, the value
"2nd October 2007 at 13:45.30.123456789" can be stored in a
LocalDateTime.
so if you need microsecond or nanosecond level information, you can not use java.util.Calendar, and you should use java.time.LocalDateTime.

Java 8 class to represent time intervals [duplicate]

This question already has answers here:
Is there a class in java.time comparable to the Joda-Time Interval?
(4 answers)
Closed 6 years ago.
Java 8 introduced a new Time & Date API, with classes like Period or Duration.
Now I'm looking for a class to represent date intervals, e.g. "from 4th August 2016 to 8th August 2016" and answer the question: do these intervals overlap. Period doesn't seem to satisfy this, since it works in an affine way, not knowing where the interval has started, only how long it takes.
Is there any Java 8 standard library class to suit my needs? Or do I have to write my own?
You could resolve the date down into a long and use an IntervalTree. Here's one I made earlier.

Generate Date from System.nanoTime() [duplicate]

This question already has answers here:
How can I convert the result of System.nanoTime to a date in Java?
(3 answers)
Closed 7 years ago.
I am writing a code for implementing Stop Watch. I capture a moment with System.nanoTime(). But I would also like to convert and store that moment into a date field. When I try to use new Date(long msec), it's giving me some absurd date-time value. Can anyone help me how to get this done?
System.nanoTime is not the current time:
This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time.
This is why you're experiencing "some absurd date-time value".
Use System.currentTimeMillis if you want the date(s) you've captured as milliseconds (see: unix time):
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

Categories

Resources