java - Time difference program -
I am using the following function to calculate time difference: i is not showing the proper output 1 month After the difference, it is showing a difference of 2 minutes.
What's wrong with my program?
public string timestamp diff timestamp t) {long T1 = T.G.time (); String str = null; Long distance; Java.util.Date date = new java.util.Date (); Long curtT = date.getTime (); Println (); System.out.println ("Current Timestamp" + is Crrut); Diff = (currT - t1) / 60; Int vested = (int) Mathflur (Diff / (1000 * 60 * 60 * 24 * 365)); Double balance = mathematics. Floor (difference% (1000 * 60 * 60 * 24 * 365)); Int days = (int) Math.floor (Balance / (1000 × 60 * 60 * 24)); Balance = Math Floor (Balance% (1000 × 60 * 60 * 24)); Int hours = (int) monastery. Floor (Balance / (1000 × 60 * 60)); Balance = mathematics. Floor (remaining% (1000 * 60 * 60)); Int Minutes = (Math) Math Floor (Balance / (1000 * 60)); Balance = Math Floor (Balance% (1000 * 60)); Int second = (mathflur) (remaining / (1000)); System.out.println ("\ nyr: DS: HH: mm: SS" + year + ":" + day + ":" + hours + ":" + minute + ":" + seconds); If (years == 0 and day == 0 & amp; hours == 0 and minute == 0) {cents = "few seconds ago"; } And if (years == 0 and day == 0 and hour == 0) {cent = minute + "minutes ago"; } And if (years == 0 and day == 0) {cent = hours + "hours ago"; } And if (years == 0 & amp;; & amp;; day == 1) {st = new simple data format} and if (years == 0 & amp;; & amp;; & amp;; day> 1) {st = New Simple Data Format ("Hm: mm A" on "MMM D" ") Format (T1); } And if (year> 0) {st = new simpleformformat ("MMM d '' hh: mm a 'on' yy '). Format (t1);} St = st.replace (" AM "," am "). Replace (" PM "," pm "); return cents;}
< Pre> import org.apache.commons.lang.time.DateUtils; import java.text.SimpleDateFormat; @Test Public Zero TestData throws exceptions {long time t1 = new SimpleDateform ("dd.mm. Yyyy ") .Pars (" 20.03.2013 "). GetTime (); Long time = System.currentTimeMillis (); String result = faucet; Long diff = Math.abs (t1-now); If (diff & lt; DateUtils.MILLIS_PER_MINUTE) {Results = "KU "Seconds ago";} and if (diff & lt; dateUtils.MILLIS_PER_HOUR) {result = (int) (diff / dateUtils.MILLIS_PER_MINUTE) + "minutes ago";} and if (diff & lt; dateUtils.MILLIS_PER_DAY) {results = (Int) (diff / dateUtils.MILLIS_PER_HOUR) + "hours ago";} and if (diff & lt; dateUtils.MILLIS_PER_DAY * 2) {Results = New SimpleDateform ("Tomorrow HH: mm A"). Format (T1); } And if (different and lit.Daily.MILLIS_PER_DAY * 365) {Results = New Simplified Format ("Hm: mm A" on "MMM D"). Format (T1); } And (Results = New SimpleDormat ("MMM D" yy "" hh: mm a). Format (T1);} Result = result. Rare ("AM", "am"). Replace ("PM" , "Pm"); println (result);}
Comments
Post a Comment