?
Solved

get the number of days from jan,1970

Posted on 2003-03-03
20
Medium Priority
?
224 Views
Last Modified: 2010-03-31
how to get the count of number of days from
a given date (say Tue Nov 12 00:00:00 GMT+05:30 2002)
0
Comment
Question by:vrbhu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 4
  • +2
20 Comments
 
LVL 4

Expert Comment

by:thanassis
ID: 8062871
<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 Comment

by:vrbhu
ID: 8063008
I wanted to calculate the number of days betweeen a given days and 1'st jan 1970.in java
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 8063049
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 8

Expert Comment

by:akshayxx
ID: 8063067
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
 
LVL 8

Expert Comment

by:akshayxx
ID: 8063074
and to know the curreent time in milliseconds u can use

long milsecs=System.currentTimeMillis();
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8063253
sciuriware is right
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8063637
>>>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8063653
Please clarify the question vrbhu. Do you want to

>>get the number of days from jan,1970

*to* a given date?
0
 

Author Comment

by:vrbhu
ID: 8070343
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 Comment

by:vrbhu
ID: 8070459
yes i want to get the number of days from jan,1970
please suggest.
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8070483
u got the answer and still asking for suggestion ??
u have any problems now , be more specific
0
 

Author Comment

by:vrbhu
ID: 8070745
yes i want to get the number of days from jan,1970
please suggest.
0
 

Author Comment

by:vrbhu
ID: 8070762
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8070765
>>
Thanx i ve got the answer.
finally i found out the number of millisecs n got the number of days out of it .
>>

sciuriware has already given you that answer vrbhu. Please accept it and close the question.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8070785
>>date but i m gettin exact number of days .

That's what your question asked for in the first place
0
 

Author Comment

by:vrbhu
ID: 8070787
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 60 total points
ID: 8070884
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
 

Author Comment

by:vrbhu
ID: 8071432
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8074687
Well vrbhu, you really ought to give sciuriware, some points. He gave the essence of this solution way back.
0
 

Author Comment

by:vrbhu
ID: 8077391
yeah thanx  sciuriware i really appreciate the solutions that u gave ..i give him 50 points more ..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question