> i read the guideline that are realy help full for writing mails.....
> > i read the guideline that are realy help full for writing mails.....
>
[quoted text clipped - 5 lines]
>
> >> Please don't top-post!
> Maybe you don't know what top-posting is and were too shy to ask?
>
> http://www.catb.org/~esr/jargon/html/T/top-post.html
> http://en.wikipedia.org/wiki/Top-posting
:) ok lan i got the idea....i wlll not top post hense further...i was
not aware about this term top post....thanks a lot
> In answer to your question:
>
> You used Date.getTime() when I meant GregorianCalendar.getTime() and you
Date dtJD = JCal.getTime();
is this not the right approch ??? plz correct me
> ignored my comment about converting from milliseconds to days. You also
plz tell me how can i get the days out of milisec...do u mean using
SimpleDateFormat.. ???
SimpleDateFormat inputFormat = new SimpleDateFormat("dd");
date = inputFormat.parse(input);
is this not the right approch ??? plz correct me
> took out your code that creates a proleptic Julian calendar. Calendar
here do u mean ??
JCal.setGregorianChange(new Date(Long.MAX_VALUE));
if yes i have added this now
> dates are very complex things so I'd make the most of
> GregorianCalendar's facilities.
>
> I'll probably ignore top-posted replies :-)
plz reply me lan, i found your only one replying....:)
Thanks
Tushar
Program :
GregorianCalendar JCal = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz
yyyy G");
JCal.setGregorianChange(new Date(Long.MAX_VALUE));
// January 1, 4713 BC
JCal.set(Calendar.YEAR, 4713);
JCal.set(Calendar.DAY_OF_YEAR, 1);
JCal.set(Calendar.ERA, GregorianCalendar.BC);
Date dtJD = JCal.getTime();
System.out.println("dtJD:" + dtJD);
System.out.println("dtJD getTimeInMillis :" +
JCal.getTimeInMillis());
System.out.println(sdf.format(dtJD));
System.out.println(dtJD.getTime());
System.out.println(JCal.get(Calendar.ERA));
Date dtToday = new Date();
System.out.println(dtToday.getTime());
System.out.println(dtToday.getTime() - dtJD.getTime());
Date formatedDate = null;
SimpleDateFormat inputFormat = new SimpleDateFormat("dd");
String input = String.valueOf(dtToday.getTime() -
dtJD.getTime());
formatedDate = inputFormat.parse(input);
SimpleDateFormat julianFormat = new
SimpleDateFormat("yyyyDDD");
String julianString = julianFormat.format(formatedDate);
System.out.println("date: " + formatedDate);
System.out.println("julian date: " + julianString);
o/p
dtJD getTimeInMillis :-210866784717556
Mon Jan 01 10:38:02 IST 4713 BC
-210866784717556
0
1162876082507
212029660800063
date: Sat Feb 22 00:00:00 IST 30166
julian date: 30166053
FYI
i was expecting the out put as per the following format
GC Julian
20061111 :: 2454051
Yr JDate
245+4051
Ref:
http://wwwmacho.mcmaster.ca/JAVA/JD.html
http://www.aavso.org
Ian Wilson - 07 Nov 2006 10:47 GMT
>>You used Date.getTime() when I meant GregorianCalendar.getTime() and you
>
> Date dtJD = JCal.getTime();
> is this not the right approch ??? plz correct me
That is correct. JCal is reference to a GregorianCalendar object, not to
a Date object. I would expect getTime() to be overridden in
GregorianCalendar to take into account all the complicated meddling by
various Roman emperors, Popes and others.
>>ignored my comment about converting from milliseconds to days. You also
>
> plz tell me how can i get the days out of milisec...do u mean using
> SimpleDateFormat.. ???
No I don't.
> SimpleDateFormat inputFormat = new SimpleDateFormat("dd");
> date = inputFormat.parse(input);
> is this not the right approch ??? plz correct me
No. Think about it.
How many milliseconds in a second?
How many seconds in an hour?
How many hours in a day?
Form the above you (and most 9 year olds too) should be able to work out
how many milliseconds in a day. From this you can convert a number of
milliseconds into a number of days.
>> took out your code that creates a proleptic Julian calendar. Calendar
>
> here do u mean ??
> JCal.setGregorianChange(new Date(Long.MAX_VALUE));
Yes.
> Program :
Its not a program, you omitted the following:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/*
* The Julian day or Julian day number (JDN) is the (integer)
* number of days that have elapsed since Monday, January 1,
* 4713 BC in the proleptic Julian calendar
*/
public class JulianDate {
public static void main(String[] args) throws ParseException {
> GregorianCalendar JCal = new GregorianCalendar();
There is a longstanding convention to use initial Capitals to name
Classes and use initial lowercase to name methods and variables. You
should refactor JCal as jCal. Better would be julianCalendar since it
makes the code more readable.
> SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz
> yyyy G");
[quoted text clipped - 15 lines]
> System.out.println(dtToday.getTime());
> System.out.println(dtToday.getTime() - dtJD.getTime());
At this point you have your Julian date in milliseconds. All you need to
do is convert it to hours ...
> Date formatedDate = null;
> SimpleDateFormat inputFormat = new SimpleDateFormat("dd");
[quoted text clipped - 9 lines]
> System.out.println("date: " + formatedDate);
> System.out.println("julian date: " + julianString);
The above is hopeless as a way of converting milliseconds to days. Try this:
long mSecPerDay = 24 * 60 * 60 * 1000;
System.out.println("There are " + mSecPerDay + " mS in 1 day.");
float days = (mSec / mSecPerDay);
System.out.println("days " + days);
> o/p
>
[quoted text clipped - 12 lines]
> GC Julian
> 20061111 :: 2454051
Thanks for posting actual and expected output.
Here's what I get from my amendements
There are 86400000 mS in 1 day.
days 2454047.0
> Yr JDate
> 245+4051
The first three digits are not a Year! they are 10000's of days.
H2O - 16 Nov 2006 05:07 GMT
hi lan
thanks , i have tryied the same and now it work with help one of my
senior coulege thanks to him also...have a look at following
program.....
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class JulianDateSimple {
private static final int MILLIS_PER_SEC = 1000;
private static final int SECS_PER_MIN = 60;
private static final int MINS_PER_HOUR = 60;
private static final int HOURS_PER_DAY = 24;
private static final int MILLIS_PER_DAY = MILLIS_PER_SEC *
SECS_PER_MIN * MINS_PER_HOUR
* HOURS_PER_DAY;
public static void main(String[] args) {
GregorianCalendar julianbaseCal = new GregorianCalendar();
julianbaseCal.clear();
julianbaseCal.set(4713, Calendar.JANUARY, 1, 12, 0, 0);
julianbaseCal.set(Calendar.ERA, GregorianCalendar.BC);
System.out.println("Base = " + julianbaseCal.getTime());
System.out.println("Base Date = " + julianbaseCal.getTime()
+ (julianbaseCal.get(Calendar.ERA) ==
GregorianCalendar.BC ? "BC" : "AD") + " ["
+ julianbaseCal.getTimeInMillis() + " millis]");
GregorianCalendar testCal = new GregorianCalendar();
testCal.clear();
testCal.setGregorianChange(new Date(Long.MAX_VALUE));
testCal.setTime(new Date());
System.out.println("Test = " + testCal.getTime());
System.out.println("Test Date = " + testCal.getTime()
+ (testCal.get(Calendar.ERA) == GregorianCalendar.BC ?
"BC" : "AD") + " ["
+ testCal.getTimeInMillis() + " millis]");
test(julianbaseCal, testCal);
}
private static void test(Calendar julianBaseDate, Calendar
testDate) {
long juliandateMillis = testDate.getTimeInMillis() -
julianBaseDate.getTimeInMillis();
double juliandateDay = juliandateMillis / (double)
(MILLIS_PER_DAY);
System.out.println("Julian Date is " + juliandateDay);
}
}