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.
Related
This question already has answers here:
How can I calculate a time difference in Java?
(19 answers)
Get difference between 2 dates in JavaScript? [duplicate]
(5 answers)
Closed 14 days ago.
I have a "start time" and an "end time" and want to determine how many hours and minutes between the times. This needs to included 24 hour shifts for example 0:00 and 0:00 would equal 24 hours.
I am brand new to Java so I need this spelled out for a total novice.
I don't even know where to start. I want for example 15:00 start time and 17:00 end time to equal 2 hrs.
My fields - Start Time, End Time and Hrs per day
I have absolutely no knowledge of Java. I'm trying to create this in an Adobe form.
Please indicate in the formula where my fields would go.
Thank you for your time.
This question already has answers here:
Java date parsing with microsecond or nanosecond accuracy
(3 answers)
Closed 5 years ago.
I'm receiving really strange date format from server. It looks 2017-03-07T15:08:01.513544Z , and strange part is six last characters before "Z", because I've seen only three symbols of milliseconds in the most responses from servers. I'm trying to parse it with SimpleDateFormat with the mask yyyy-MM-dd'T'HH:mm:ss.SSS'Z', and it works on all android versions except api 16 (4.1). In developer.android.com I saw example with the mask like .SSSXXX, but as result I have error, because system doesn't know symbol 'X'. So, have you ever faced with similar date format?
The answer is straightforward but entails a little more than just the answer.
Instant instantFromServer = Instant.parse("2017-03-07T15:08:01.513544Z");
To use this on Android you will need to get the ThreeTenABP library. It contains the date and time classes described in JSR-310 of which Instant is one. See the links below.
So, have you ever faced with similar date format?
01.513544 means 1.513544 seconds, or 1 second 513 milliseconds 544 microseconds, or 1 second 513544000 nanoseconds. There are many ways to put it. I have worked with IBM mainframes that routinely gave us timestamps with microsecond precision, that is, 6 decimals on the seconds. I suppose as computers are getting faster, accuracy requirements are getting stricter, so we may see more of these in the future. While I believe that SimpleDateFormat cannot handle these, the classes in JSR-310 generally have nanosecond precision and parse strings with variable number of decimals out of the box.
Links
ThreeTenABP
Question: How to use ThreeTenABP in Android Project
This question already has answers here:
Parsing time strings like "1h 30min"
(8 answers)
Closed 6 years ago.
Is there any libraries that is able to take a string such as 5d 1h 2m 15s and add it to a java date / java Calendar?
ie a system property will be set as 5d 1h 2m 15s
We will read in the system property and add this amount of time to the current date.
Otherwise I will have to implement this as a long in milliseconds.
you'll need a bit of parsing to extract the component element but Joda-Time's duration should help you out
http://joda-time.sourceforge.net/apidocs/org/joda/time/Duration.html
If you are using Java8 joda-time's concept were integrated so no need to external dependencies
https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html
once you have a duration adding it to the current date time should be trivial
Java8 and jodaTime
Instant ajustedTime = Instant.now().plus(yourDurationInstance);
you can convert to and from Java's date pretty easily, others have already answered here
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.
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.