0

While referring to a particular course I came across the following code to retrieve the current day:

int julianStartDay = Time.getJulianDay(System.currentTimeMillis(),   dayTime.gmtoff);
long dateTime;
dateTime = dayTime.setJulianDay(julianStartDay);
day = getReadableDateString(dateTime);

     private String getReadableDateString(long time){
          SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("E MMM d");
            return shortenedDateFormat.format(time);
        }

My doubt is why are we using this julian method instead of just directly extracting the day from the Date class object which gives the current date and time.

ghostrider
  • 2,046
  • 3
  • 23
  • 46
  • Two questions: 1. You're asking why your example uses `getJulianDay()` instead of directly using `System.currentTimeMilis()`? and 2. How old is this particular example? – ricky3350 Aug 23 '15 at 15:24
  • 1. Yes..and also cant we use the Date class object directly to get the current day? 2. Regarding the oldness I have no idea but I am guessing its after 2012.. – ghostrider Aug 23 '15 at 15:32
  • The above piece of code seems to do two things: (1) change the value of the variable `dayTime` to today at midnight, in its original time zone, and (2) set `day` to a string that represents today. How do you propose to do the first part with `Date`? – RealSkeptic Aug 23 '15 at 16:12
  • I am proposing to replace this two statements with just one statement that extracts the day part.. – ghostrider Aug 23 '15 at 17:17

1 Answers1

2

Is your application related to the Eastern Orthodox religious calendar? As far as I'm aware, that's the only place the Julian calendar is still in use.

The Java Date and Calendar classes use the Gregorian calendar by default. (Calendar.getInstance methods return a GregorianCalendar object unless one of two specific locales is specified.) If your application needs to use the Julian calendar instead, that would explain this implementation.

super_aardvark
  • 1,825
  • 1
  • 14
  • 19