Can anyone give me the link to an online calculator or an accurate formula to calculate the number of milliseconds since 1970 to a given date? i have a function which calculates this. But I want to compare the output of my function with the output of some inbuilt function in java or the output of some online calculator which does this same computation? I've tried out this
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-4"));
cal.set(2000, 01, 21, 04, 开发者_Go百科33, 44);
long mynum=cal.getTimeInMillis();
System.out.println(mynum);
The problem is that the "mynum" value keeps changing for every run.. So i can't do a correct comparison.
Can anyone direct me in the correct path?
They keep changing because you set all the fields except the milliseconds, which are thus the number of milliseconds at the current time.
Call cal.set(Calendar.MILLISECOND, 0)
or cal.clear()
before setting the other fields, and the values shouldn't vary anymore.
精彩评论