PDA

View Full Version : Please help: regarding Calendar.


jkim
08-01-2007, 09:48 AM
Hi,

This is my first post here. Anyway, I am very experienced in using Sun JDK, but I have a problem that I need resolved by someone experienced in Microsoft JDK.

I am coding a cross-platform piece of code, which explicitly needs to be backwards (and forwards) compatible, between various versions of Java.

However, another problem is that it also needs to be VM cross compatible (between Sun JVM 1.2+ and Microsoft JVM 6.0+).

The requirement is to compile using Microsoft JDK (jvc.exe) 6.00.8343.

I have a piece of code that looks something like this:
long time = Calendar.getInstance(TimeZone.get...).getTimeInMillis();

This works fine under Sun JDK (1.3.1), but under Microsoft, it spits out the following error:
java\xxx\yyy\Zzzzz.java(4129,57) : error J0203: Cannot access protected member 'long getTimeInMillis()' in class 'Calendar' from class 'Zzzzz.Zinner'

My question is this:
Where could I find the API specification document for the Microsoft JDK Calendar class; or what would be another way of achieving this (another method thats both public and common to both JDK perhaps)?

Aradon
08-01-2007, 06:46 PM
I couldn't find any api specifications for Microsoft's JVM. The closest I found was a message from Microsoft telling users to move off their JVM by December of 2007 to Sun's as they will no longer be supporting it (Sun won their lawsuit).

But to help with the error, have you tried seperating it out? Or maybe moving paren's around? For example..


Long time = (Calendar.getInstance(TimeZone.get...)).getTimeInMillis();

/// or

Calendar ctemp = Calendar.getInstance(TimeZone.get..);
Long time = ctemp.getTimeInMillis();


It seems odd to me that Microsoft wouldn't provide this functionality despite it being in the java source code.

jkim
08-02-2007, 01:07 AM
Yes, I'm aware of the announcement by Microsoft regarding their JVM. However, it's the current policy of the company to compile using the Microsoft SDK rather than the Sun SDK; and because I have no say in the matter, it's not an option for me to develop to Sun JVM specifications.

I much prefer the Sun JVM, since everything is documented, and I know where to go if I have a hitch.

As for your suggestion regarding separation - yes, that was the first thing I tried.

Looks like Microsoft have made the getTimeInMillis() method protected.
:(

Aradon
08-02-2007, 08:00 AM
I can only suspect that Microsoft did this in order to erase compatibility issues with some of their other programs that convert Java code to C# code (Why would you want that anyways?) or other programs they created on the fly. It seems odd that they would make it protected, however. Have you tried, instead, using the GregorianCalendar?

An example can be seen here:

Current Time (http://www.exampledepot.com/egs/java.util/GetCurTime.html?l=rel)
Current Time another Timezone (http://www.exampledepot.com/egs/java.util/GetTimeOtherZone.html?l=rel)

Adding on, of course, that you do

At the very least you may be able to convert from the current time (hours, minutes, etc) to the millisecond you need. I mean, we know what epoch is and we know the current day/time so you can figure it out from there. (Go Math).

jkim
08-06-2007, 09:16 AM
Thanks for the response.

Rather than going through the tedium of mathematically calculating the ms figure, I'd decided to use the System.currentTimeInMillis() method, which, lucky for me, was not protected/private.

cash1981
08-10-2007, 01:51 PM
There is an java api which is called joda-time which is helpful for date stuff.
I don't know the implementation behind it since i only use SUN's JDK, but it is worth a try.

http://joda-time.sourceforge.net/