Re: Help in CalenderAPI
- From: "H2O" <mail.tlad@xxxxxxxxx>
- Date: 2 Nov 2006 02:40:10 -0800
I have found some details about the Julian calendar as follows:
The Julian date for 2006: JAN: 01:12:01:59 is 2453737.00138
245 represent the year digits for year 2006
3737 represent the date fir 1 Jan
..00138 represents the time for 12:01:59
Julian date change as per every day 12 noon it increase one digit in
it.
As per ref from
http://www.aavso.org/observing/aids/jdcalendar.shtml
Also chk this calendar where Julian date is 20. October 2006 for 02
November 2006
As per ref from
http://www.calendar.sk/julian_calendar-en.php
I have tried the pure "GregorianCalendar" class from jdk1.4 API and
its setGregorianChange method but not getting as per the expected
Julian date format. Using the "setGregorianChange()" i have setting
the cutover date to Long.MAX_VALUE it means GregorianCalendar now have
to act as per the Julian calendar ...so after setting the cutover date
it return me changed date using "getGregorianChange()" but that was
not the Julian date of the current date...as expected or as per above
both scenario. Even though the last two digits are nowhere equal to the
actual Julian date.
Program
GregorianCalendar cal = new GregorianCalendar();
cal.setGregorianChange(new Date(Long.MAX_VALUE)); // setting the
calendar to act as a pure Julian calendar.
// cal.set(Calendar.DATE, new Date().getDate()); // seting the current
date
// Date todayJD = cal.getGregorianChange(); // getting the changed date
after the setGregorianChange
Date todayJD = cal.getTime(); // getting the calculated time of
today's Julian date
SimpleDateFormat sdfJulianDate = new SimpleDateFormat("yyDDD");
SimpleDateFormat sdfJuliandayOfYear = new SimpleDateFormat("DDD");
System.out.println("today Date = " + new Date());
System.out.println("Today as julian date = " +
sdfJulianDate.format(todayJD));
System.out.println("Today as day of year = " +
sdfJuliandayOfYear.format(todayJD));
OUTPUT:
USING : Date todayJD = cal.getGregorianChange();
Today Date = Thu Nov 02 15:17:05 IST 2006
Today as julian date = 94229
Today as day of year = 229
USING : cal.set(Calendar.DATE, new Date().getDate());
Today Date = Thu Nov 02 15:19:22 IST 2006
Today as julian date = 06319
Today as day of year = 319
USING : Date todayJD = cal.getTime();
Today Date = Thu Nov 02 15:17:59 IST 2006
Today as julian date = 06306
Today as day of year = 306
There is one another concept i found to get the Julian day of the year
as per the Julian day chart mention on nasa site
(http://angler.larc.nasa.gov/armsgp/JulianDayChart.html) and i m
getting the moth of the year that is 306 for nov 02 2006 using
getTime() method in above code then the out put is right for Julian
day. But it was not as per the expected Julian date format. So in
conclusion we can only able to retrieve the day of year for the Julian
calendar. hope their will be a solution for this problem in java api
.....else we allways have to depend upon the third party api that was
not accepteble some times.....
Kindly chk chart on the site
http://angler.larc.nasa.gov/armsgp/JulianDayChart.html
http://weather.uwaterloo.ca/julian.html
http://www.fs.fed.us/raws/book/julian.shtml
Thanks,
Tushar
H2O wrote:
thanks lan,
i have tryied your suggesion but it was fail to my exceptions
o/p is Julian 2006 10 2
what i expected was
Current Calendar date : 2006 11 1
Julian date for it : 2454041.0 /// as expected result from julian date
converter
for more information about julian date
http://www.aavso.org/observing/aids/jdcalendar.shtml
cureent julian year is 245 and julian day is 4041
the date i m geting using the getGregorianChange is no where same as
julian day or julian year...i was strugling to get it using pure java
api...there are many third party api which i can use but client requied
and trust on jdk only....and as mention on jdk doc the
GregorianCalender need to act as pure julian calender if it for it
using newDate(Long.MaxValue)
even i tryied using simple date format to format the date i get from
getGregorianChange
and date.getTime() but fail to foamt as per the julian astronomy foamat
hope will find the solution using jdk but was doubt abt it..because i
found the bug reported in jdk bud database about it...but nowhere found
the solution
Api Desc :
setGregorianChange
public void setGregorianChange(Date date)Sets the GregorianCalendar
change date. This is the point when the switch from Julian dates to
Gregorian dates occurred. Default is October 15, 1582. Previous to
this, dates will be in the Julian calendar.
To obtain a pure Julian calendar, set the change date to
Date(Long.MAX_VALUE). To obtain a pure Gregorian calendar, set the
change date to Date(Long.MIN_VALUE).
Parameters:
date - the given Gregorian cutover date.
Ian Wilson wrote:
H2O wrote:
Hi can any one help me out to convert the current date to julian date
using java api???
i have tryied hard for the solution using GregorianCalender and
SimpleDateFormat but still not able to conver the date to the julian
date
i have used the follwing method to do so ...
GregorianCalendar calendar = new GregorianCalendar();
I think you are missing
calendar.setTime(new Date());
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy.MM.dd G 'at' hh:mm:ss z");
Date date = new Date(Long.MAX_VALUE);
System.out.println("Formated date " + sdf.format(date));
calendar.setGregorianChange(date);
Date date1 = calendar.getGregorianChange();
You are getting the Julian-Gregorian transition date which you just set.
What you probably wanted is
Date date1 = calendar.getTime();
But Date will give you a Gregorian Date.
System.out.println("Formated date1 " + sdf.format(date1));
Try something like
System.out.println("Julian " + calendar.get(Calendar.YEAR)
+" " + calendar.get(Calendar.MONTH)
+" " + calendar.get(Calendar.DATE));
}
but not geting the current date so if any one knw about the same then
plz let me knw ASAP
I find newsgroups are good if you can wait a day or so for solutions.
.
- References:
- Help in CalenderAPI
- From: H2O
- Re: Help in CalenderAPI
- From: Ian Wilson
- Re: Help in CalenderAPI
- From: H2O
- Help in CalenderAPI
- Prev by Date: Re: Java MP3 audio recorder
- Next by Date: Re: Help in CalenderAPI
- Previous by thread: Re: Help in CalenderAPI
- Next by thread: Re: Help in CalenderAPI
- Index(es):
Relevant Pages
|