3

I am trying to extract the id 41794 from a website. But the said number depends on the start date(today's date). See snippet below from the site,

'index.cfm?fuseaction=c_availabilityGrid.displayAvailabilityGrid&startDate=41794&timeSpan=ww,2&showBeds=1&showMlos=0&showprice=1'

I am interested to know how the value 41794 is obtained from today's date so that i can put that logic in my code.

Is there any function in java which takes input as date and returns the number as mentioned above?

Any help in this matter would be greatly appreciated.

Girish Nair
  • 5,148
  • 5
  • 40
  • 61
  • http://stackoverflow.com/questions/9754600/converting-epoch-time-to-date-string – TheLostMind Jun 04 '14 at 05:58
  • Search using a different date and check what is the is returned, then u can try to find a logic comparing both – fmodos Jun 04 '14 at 05:58
  • It seems an odd value, perhaps it's 41,794 days since some epoch (like January 1, 1900)? Does the value change during a day, and does it progress linearly over time? At what rate? – Elliott Frisch Jun 04 '14 at 05:59
  • @Elliott - The value varies over the day. Yesterday it was 41793, and today it is 41794. Seems like an auto increment. – user3690060 Jun 04 '14 at 06:10

2 Answers2

6

It looks like the number of days since 1 Jan 1900, possibly with a leap year screwup or two.

Take a look at http://www.timeanddate.com/countdown/to?p0=198&year=1900&month=1&day=1&hour=0&min=0&sec=0

Microsoft Excel uses a system like this. Google "Excel serial date".

NPE
  • 486,780
  • 108
  • 951
  • 1,012
1

The answer by NPE is correct. Using the modern date-time API*, it can be confirmed as shown below:

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;

public class Main {
    public static void main(String[] args) {
        LocalDateTime ref = LocalDate.of(1900, Month.JANUARY, 1).atStartOfDay();
        LocalDateTime result = ref.plus(Duration.ofDays(41794));
        System.out.println(result);
    }
}    

Output:

2014-06-06T00:00

Learn more about the the modern date-time API* from Trail: Date Time.


* For any reason, if you have to stick to Java 6 or Java 7, you can use ThreeTen-Backport which backports most of the java.time functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring and How to use ThreeTenABP in Android Project.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110