Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Java Date and Excel Date

Thread view: 
aaronfude@gmail.com - 13 Sep 2006 22:30 GMT
Hi,

In Excel, the date represents the number of days since Jan/1/1990, with
the number 1 representing that date.

May/1/2006 is represented by .

So the following ought to convert that number to a java date:

GregorianCalendar gc = new GregorianCalendar(1900, Calendar.JANUARY,
1);
gc.setTimeInMillis(gc.getTimeInMillis()+ (38838L-1)*24*60*60*1000);
System.out.println(gc.getTime());

But I get

Tue May 02 01:00:00 EDT 2006

Am I doing something wrong or does Excel count days wrong?

Many thanks in advance!

Aaron Fude
Arne Vajhøj - 13 Sep 2006 22:48 GMT
> In Excel, the date represents the number of days since Jan/1/1990, with
> the number 1 representing that date.
>
> May/1/2006 is represented by .

I think you lost 38838 here.

> So the following ought to convert that number to a java date:
>
[quoted text clipped - 8 lines]
>
> Am I doing something wrong or does Excel count days wrong?

The 00:00:00 versus 01:00:00 is EDT versus EST.

I would suggest replacing:

gc.setTimeInMillis(gc.getTimeInMillis()+ (38838L-1)*24*60*60*1000);

with:

gc.add(Calendar.DATE, 38838-1);

The May 02 versus May 01 is a bug in Excel.

Try look at the date 60 in Excel.

It is 29-Feb-1900.

That date does not exist in real life.

(remember: only if multipla of 4, but if multipla of 100 only if
mulipla of 400)

Arne
Babu Kalakrishnan - 14 Sep 2006 05:09 GMT
> In Excel, the date represents the number of days since Jan/1/1990, with
> the number 1 representing that date.
>
> May/1/2006 is represented by .
>
> So the following ought to convert that number to a java date:

If you're looking for s third party class, try JFreeChart (Or rather
its companion utility library JCommon) - it contains a class named
SpreadSheetDate which IIRC models the date numbers used in Excel.

BK


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.