iam working with a real time project where i got a requirement to find seconds since 1970 january 1.I have used the following code to find out seconds but is giving wrong result.The code is as follows.
public long returnSeconds(int year, int month, int date) {
Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();
calendar1.set(1970, 01, 01);
calendar2.set(year, month, date);
long milliseconds1 = calendar1.getTimeInMillis();
long milliseconds2 = calendar2.getTimeInMillis();
long diff = milliseconds2 - milliseconds1;
long seconds = diff / 1000;
return seconds;
}
In the above in place of year,month,date
I'm passing 2011,10,1
and iam getting
1317510000
but the correct answer is
1317427200
Any help regarding this is very useful to me.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…