# get the number of days from jan,1970

how to get the count of number of days from
a given date (say Tue Nov 12 00:00:00 GMT+05:30 2002)
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
<script language = javascript>
function timetill(year,month,day){
countdown=new Date(year,month-1,day);
now = new Date();
count_sec = Math.round((countdown - now) / 1000);
days = Math.floor(count_sec/(60*60*24))
hours = Math.floor((count_sec - (days*60*60*24))/(60*60))
minutes = Math.floor((count_sec- (days*60*60*24 + hours*60*60))/60)
sec = count_sec- (days*60*60*24 + hours*60*60 + minutes*60)
str = days +" days, "+ hours +" hours, "+ minutes +" miniutes, "+ sec +" seconds"
obj_count_sec_display = document.getElementById("count_sec_display");

obj_count_sec_display.innerHTML = str+" till " + month + "/" + day +"/"+year;
setTimeout("timetill(2003,01,01)",1000);
}
timetill(2003,01,01);
</script>
0
Author Commented:
I wanted to calculate the number of days betweeen a given days and 1'st jan 1970.in java
0
Commented:
As time(1-1-1970) is 0L,
you might just divide the time of your given date by 1000*60*60*24 (from milliSeconds to days).
;JOOP!

0
Commented:
its as simple as following..

import java.util.Calendar;
Calendar mycal=new Calendar();
// u might want to set the locale and timezone..
//now set the values for day month year and time

mycal.set(Calendar.YEAR,2003);
mycal.set(Calendar.DAY_OF_MONTH,5);
mycal.set(Calendar.MONTH,3);
//similarly u can set the hour minute and seconds ..
//then do this
long milSecs= mycal.getTimeInMillis();

int days= milSecs/(1000*24*60*60);
0
Commented:
and to know the curreent time in milliseconds u can use

long milsecs=System.currentTimeMillis();
0
Commented:
sciuriware is right
0
Commented:
>>>>how to get the count of number of days from
a given date

that means he doenst wish to perfom just for current time .. he would like to first set a desired date .. then calculate the number of days since 1970,1,jan
custom dates can be made with java.util.Calendar.. since they made the corresponding APIs deprecatred in java.util.Date
0
Commented:
Please clarify the question vrbhu. Do you want to

>>get the number of days from jan,1970

*to* a given date?
0
Author Commented:
Thanx i ve got the answer.
finally i found out the number of millisecs n got the number of days out of it .
0
Author Commented:
yes i want to get the number of days from jan,1970
0
Commented:
u have any problems now , be more specific
0
Author Commented:
yes i want to get the number of days from jan,1970
0
Author Commented:
Acutually i tried out with getting millisecs elasped(from 1,jan ,1970)with a given date but i m gettin exact number of days .
SimpleDateFormat l_oDateFormat = null;
java.util.Date l_oDate = null;
try
{
l_oDateFormat = new SimpleDateFormat("ddMMMyy");
System.out.println("seq-num "  + l_iSeqNumber);
l_oDate = l_oDateFormat.parse("12NOV02");
int days = l_oDate.getTime() + l_lOneHour)/ (l_lOneHour * 24);
i m not getting exact value of days...

0
Commented:
>>
Thanx i ve got the answer.
finally i found out the number of millisecs n got the number of days out of it .
>>

0
Commented:
>>date but i m gettin exact number of days .

0
Author Commented:
Acutually i tried out with getting millisecs elasped(from 1,jan ,1970)with a given date but i m gettin exact number of days .
SimpleDateFormat l_oDateFormat = null;
java.util.Date l_oDate = null;
try
{
l_oDateFormat = new SimpleDateFormat("ddMMMyy");
System.out.println("seq-num "  + l_iSeqNumber);
l_oDate = l_oDateFormat.parse("12NOV02");
int days = l_oDate.getTime() + l_lOneHour)/ (l_lOneHour * 24);
i m not getting exact value of days...

0
Commented:
import java.text.*;
import java.util.*;

public class DaysSinceJan70 {

public static void main(String[] args) throws Exception {
final int DAYS_DIVISOR = 1000*60*60*24;
SimpleDateFormat l_oDateFormat = new SimpleDateFormat("ddMMMyy");
Date d = l_oDateFormat.parse("03JAN70");
/**
* getTime() docs:
* "Returns the number of milliseconds since January 1,
* 1970, 00:00:00 GMT represented by this Date object"
*
* Since date is midnight January 3rd, prints 1
*/
System.out.println(d.getTime() / DAYS_DIVISOR);
}

}

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Acutually i tried out with getting millisecs elasped(from 1,jan ,1970)with a given date but i m gettin exact number of days .
SimpleDateFormat l_oDateFormat = null;
java.util.Date l_oDate = null;
try
{
l_oDateFormat = new SimpleDateFormat("ddMMMyy");
System.out.println("seq-num "  + l_iSeqNumber);
l_oDate = l_oDateFormat.parse("12NOV02");
int days = l_oDate.getTime() + l_lOneHour)/ (l_lOneHour * 24);
i m not getting exact value of days...

0
Commented:
Well vrbhu, you really ought to give sciuriware, some points. He gave the essence of this solution way back.
0
Author Commented:
yeah thanx  sciuriware i really appreciate the solutions that u gave ..i give him 50 points more ..
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.