Java Calendar problem

Hello
I have problems with Java Calendar class:
Problem 1:
I try to set Java calendar to specific date, but an exception is thrown. Problematic dates are 19210501 and 19420403 (yyyymmdd) at midnight (hour of day = 0, minutes = 0, seconds = 0, milliseconds = 0). Setting other dates between 15000101 and 22000101 work OK. Exception is thrown when calendar calculates new values. Note that exception is NOT thrown if I do not set hour / minute / second fields!
Problem 2:
I set Java calendar to specific date A and convert that date to timeInMillis. Then I set this timeInMillis to calendar and convert it to date B. For certain dates A != B. Problematic dates are 19210501 and 19420403 (yyyymmdd) at midnight (hour of day = 0, minutes = 0, seconds = 0, milliseconds = 0). Setting other dates between 15000101 and 22000101 work OK.
These problems occur if timeZone = "Europe/Helsinki". Problem does not occur if timeZone = "EET" or "GMT".
Example code of this problem is below:
==================
package z_javaexperiments5;
import java.util.Calendar;
import java.util.TimeZone;
public class CalendarProblem {
public static void main(String[] args) {
CalendarProblem main = new CalendarProblem();
System.out.println( "RunSetCalendars" );
TimeZone timeZone = TimeZone.getTimeZone( "GMT" );
main.runSetCalendars( timeZone, 19420403000000000L );
main.runSetCalendars( timeZone, 19210501000000000L );
main.runSetCalendars( timeZone, 19210502000000000L );
timeZone = TimeZone.getTimeZone( "EET" );
main.runSetCalendars( timeZone, 19420403000000000L );
main.runSetCalendars( timeZone, 19210501000000000L );
main.runSetCalendars( timeZone, 19210502000000000L );
timeZone = TimeZone.getTimeZone( "Europe/Helsinki" );
main.runSetCalendars( timeZone, 19420403000000000L );
main.runSetCalendars( timeZone, 19210501000000000L );
main.runSetCalendars( timeZone, 19210502000000000L );
Calendar setCalendar1( TimeZone timeZone, long dateTimeYYYYMMDDHHMMSSsss ) {
Calendar calendar = Calendar.getInstance(timeZone);
calendar.clear();
System.out.println( "setCalendar1 timeZone = " + calendar.getTimeZone().getID());
int year = (int)( dateTimeYYYYMMDDHHMMSSsss / 10000000000000L );
int month = (int)(( dateTimeYYYYMMDDHHMMSSsss % 10000000000000L ) / 100000000000L ) - 1;
int day = (int)(( dateTimeYYYYMMDDHHMMSSsss % 100000000000L ) / 1000000000 );
int hour = (int)(( dateTimeYYYYMMDDHHMMSSsss % 1000000000 ) / 10000000 );
int min = (int)(( dateTimeYYYYMMDDHHMMSSsss % 10000000 ) / 100000 );
int sec = (int)(( dateTimeYYYYMMDDHHMMSSsss % 100000 ) / 1000 );
int mSec = (int)( dateTimeYYYYMMDDHHMMSSsss % 1000 );
System.out.println( year + "." + (month+1) + "." + day + " " + hour + ":" + min + ":" + sec + "." + mSec );
calendar.set( year, month, day );
calendar.set( Calendar.HOUR_OF_DAY, hour );
calendar.set( Calendar.MINUTE, min );
calendar.set( Calendar.SECOND, sec );
calendar.set( Calendar.MILLISECOND, mSec );
calendar.setLenient( false ); // Reject illegal values
try {
calendar.get( Calendar.SECOND ); // Recalc values
} catch ( IllegalArgumentException e ) {
throw new RuntimeException("Invalid argument: Cannot convert long to dateTimeYYYYMMDDHHMMSSsss, long = " + dateTimeYYYYMMDDHHMMSSsss + " Exception message = " + e.getMessage());
return calendar;
Calendar setCalendar2( TimeZone timeZone, long dateTimeYYYYMMDDHHMMSSsss ) {
Calendar calendar = Calendar.getInstance(timeZone);
System.out.println( "setCalendar2 timeZone = " + calendar.getTimeZone().getID());
calendar.clear();
int year = (int)( dateTimeYYYYMMDDHHMMSSsss / 10000000000000L );
int month = (int)(( dateTimeYYYYMMDDHHMMSSsss % 10000000000000L ) / 100000000000L ) - 1;
int day = (int)(( dateTimeYYYYMMDDHHMMSSsss % 100000000000L ) / 1000000000 );
int hour = (int)(( dateTimeYYYYMMDDHHMMSSsss % 1000000000 ) / 10000000 );
int min = (int)(( dateTimeYYYYMMDDHHMMSSsss % 10000000 ) / 100000 );
int sec = (int)(( dateTimeYYYYMMDDHHMMSSsss % 100000 ) / 1000 );
int mSec = (int)( dateTimeYYYYMMDDHHMMSSsss % 1000 );
System.out.println( "Initial dateTime = " + year + "." + (month+1) + "." + day + " " + hour + ":" + min + ":" + sec + "." + mSec );
calendar.set( year, month, day );
if ( hour != 0 )
calendar.set( Calendar.HOUR_OF_DAY, hour );
else
calendar.clear( Calendar.HOUR_OF_DAY );
if ( min != 0 )
calendar.set( Calendar.MINUTE, min );
else
calendar.clear( Calendar.MINUTE );
if ( sec != 0 )
calendar.set( Calendar.SECOND, sec );
else
calendar.clear( Calendar.SECOND );
if ( mSec != 0 )
calendar.set( Calendar.MILLISECOND, mSec );
else
calendar.clear( Calendar.MILLISECOND );
calendar.setLenient( false ); // Reject illegal values
try {
calendar.get( Calendar.SECOND ); // Recalc values
} catch ( IllegalArgumentException e ) {
throw new RuntimeException("Invalid argument: Cannot convert long to dateTimeYYYYMMDDHHMMSSsss, long = " + dateTimeYYYYMMDDHHMMSSsss + " Exception message = " + e.getMessage());
long millis = calendar.getTimeInMillis();
//System.out.println( "Initial dateTime = " + millis );
calendar = Calendar.getInstance(timeZone);
calendar.clear();
calendar.setTimeInMillis( millis );
int year2 = calendar.get( Calendar.YEAR );
int month2 = calendar.get( Calendar.MONTH );
int day2 = calendar.get( Calendar.DAY_OF_MONTH );
int hour2 = calendar.get( Calendar.HOUR_OF_DAY );
int min2 = calendar.get( Calendar.MINUTE );
int sec2 = calendar.get( Calendar.SECOND );
int mSec2 = calendar.get( Calendar.MILLISECOND );
System.out.println( "Final dateTime = " + year2 + "." + (month2+1) + "." + day2 + " " + hour2 + ":" + min2 + ":" + sec2 + "." + mSec2 );
if (( year != year2 ) || ( month != month2 ) || ( day != day2 ) || ( hour != hour2 ) || ( min != min2 ) || ( sec != sec2 ) || ( mSec != mSec2 ))
System.out.println( "setCalendar2 failed, dates are not equal" );
return calendar;
void runSetCalendars( TimeZone timeZone, long dateTimeYYYYMMDDHHMMSSsss ) {
System.out.println( "" );
System.out.println( "runSetCalendars dateTimeYYYYMMDDHHMMSSsss = " + dateTimeYYYYMMDDHHMMSSsss );
try {
setCalendar1( timeZone, dateTimeYYYYMMDDHHMMSSsss );
} catch ( RuntimeException e ) {
System.out.println( "setCalendar1 failed, dateTimeYYYYMMDDHHMMSSsss = " + dateTimeYYYYMMDDHHMMSSsss + " Exception = " + e.toString());
Calendar calendar = null;
try {
calendar = setCalendar2( timeZone, dateTimeYYYYMMDDHHMMSSsss );
long timeInMillis = calendar.getTimeInMillis();
calendar.clear();
calendar.setTimeInMillis( timeInMillis );
} catch ( RuntimeException e ) {
System.out.println( "setCalendar2 failed, dateTimeYYYYMMDDHHMMSSsss = " + dateTimeYYYYMMDDHHMMSSsss + " Exception = " + e.toString());
==================
Program output is below:
==================
RunSetCalendars
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19420403000000000
setCalendar1 timeZone = GMT
1942.4.3 0:0:0.0
setCalendar2 timeZone = GMT
Initial dateTime = 1942.4.3 0:0:0.0
Final dateTime = 1942.4.3 0:0:0.0
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19210501000000000
setCalendar1 timeZone = GMT
1921.5.1 0:0:0.0
setCalendar2 timeZone = GMT
Initial dateTime = 1921.5.1 0:0:0.0
Final dateTime = 1921.5.1 0:0:0.0
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19210502000000000
setCalendar1 timeZone = GMT
1921.5.2 0:0:0.0
setCalendar2 timeZone = GMT
Initial dateTime = 1921.5.2 0:0:0.0
Final dateTime = 1921.5.2 0:0:0.0
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19420403000000000
setCalendar1 timeZone = EET
1942.4.3 0:0:0.0
setCalendar2 timeZone = EET
Initial dateTime = 1942.4.3 0:0:0.0
Final dateTime = 1942.4.3 0:0:0.0
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19210501000000000
setCalendar1 timeZone = EET
1921.5.1 0:0:0.0
setCalendar2 timeZone = EET
Initial dateTime = 1921.5.1 0:0:0.0
Final dateTime = 1921.5.1 0:0:0.0
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19210502000000000
setCalendar1 timeZone = EET
1921.5.2 0:0:0.0
setCalendar2 timeZone = EET
Initial dateTime = 1921.5.2 0:0:0.0
Final dateTime = 1921.5.2 0:0:0.0
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19420403000000000
setCalendar1 timeZone = Europe/Helsinki
1942.4.3 0:0:0.0
setCalendar1 failed, dateTimeYYYYMMDDHHMMSSsss = 19420403000000000 Exception = java.lang.RuntimeException: Invalid argument: Cannot convert long to dateTimeYYYYMMDDHHMMSSsss, long = 19420403000000000 Exception message = HOUR_OF_DAY
setCalendar2 timeZone = Europe/Helsinki
Initial dateTime = 1942.4.3 0:0:0.0
Final dateTime = 1942.4.3 1:0:0.0
setCalendar2 failed, dates are not equal
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19210501000000000
setCalendar1 timeZone = Europe/Helsinki
1921.5.1 0:0:0.0
setCalendar1 failed, dateTimeYYYYMMDDHHMMSSsss = 19210501000000000 Exception = java.lang.RuntimeException: Invalid argument: Cannot convert long to dateTimeYYYYMMDDHHMMSSsss, long = 19210501000000000 Exception message = MINUTE
setCalendar2 timeZone = Europe/Helsinki
Initial dateTime = 1921.5.1 0:0:0.0
Final dateTime = 1921.5.1 0:20:8.0
setCalendar2 failed, dates are not equal
runSetCalendars dateTimeYYYYMMDDHHMMSSsss = 19210502000000000
setCalendar1 timeZone = Europe/Helsinki
1921.5.2 0:0:0.0
setCalendar2 timeZone = Europe/Helsinki
Initial dateTime = 1921.5.2 0:0:0.0
Final dateTime = 1921.5.2 0:0:0.0
==================
Why does the program fail when timeZone = "Europe/Helsinki"?

Could it be related to the time zone changes which occurred at about this time?
http://www.timeanddate.com/worldclock/clockchange.html?n=101&year=1921

Similar Messages

  • Java Session problem while sending mail(using javamail) using Pl/SQL

    Hello ...
    i am using Java stored procedure to send mail. but i'm getting java session problem. means only once i can execute that procedure
    pls any help.

    props.put("smtp.gmail.com",host);I doubt javamail recognizes the 'smtp.gmail.com' property. I think it expects 'mail.host'. Of course since it cannot find a specified howt it assumes by default localhost
    Please format your code when you post the next time, there is a nice 'code' button above the post area.
    Mike

  • Java Programming Problem

    Hi all,
    I was looking for this java programming problem which had to do with a large building and there was some gallons of water involved in it too somehow and we had to figure out the height of the buiding using java. This problem is also in one of the java books and I really need to find out all details about this problem and the solution. NEED HELP!!
    Thanks
    mac

    Yes, it will. The water will drain from the bottom of
    the tank until the pressure from the water inside the
    tank equals the pressure from the pipe. In other
    words, without a pump, the water will drain out until
    there is the same amount of water in the tank as in
    the pipe The water pressure depends on the depth of the water, not the volume. So once the depth of the water inside the pipe reaches the same depth as the water inside the tank it will stop flowing. This will never be above the height of the tank.
    I found this applet which demonstrates our problem. If you run it you can drag the guy up to the top, when water in his hose reaches the level of the water in the tank it will stop flowing out.

  • Java Uninstall Problem

    Java Uninstall Problem
    This all came about because of a failed uninstall, using Your Uninstaller.
    The {Java runtime which is all I want) is not listed now & I tried all the other fix bad uninstall type features, all to no avail.} )
    When I DL & run the latest package (jxpiinstall-6u11-fcs-bin-b90-windows-i586-25_nov_2008.exe}
    & run it I get:
    1st message:
         "This software has already been installed on your computer.
         Would you like to install it?"
    If I say no, it exits.
    If I say yes, I get this second message:
         :This action is only valid for products that are currently installed."
    So Now I have no Java & have no idea what to do.
    Any help would be greatly appreciated.
    Thanks, Neuromancer23

    Sorry...after posting it i realized there was a more appropriate forum, of which it took quiet awhile to find.)
    Now that I know where to find the forum list I will never double-post again.
    I'll close the question if I can

  • Question about Sun Java Calendar Server 7

    You downloadable forum, at [http://www.sun.com/software/products/calendar_srvr/get_it.jsp|http://www.sun.com/software/products/calendar_srvr/get_it.jsp],
    leaves one with two questions.
    -What databases are needed/supported by this MessageBoard System for backend storage?
    -What are the licensing details? May the MessageBoard/Communications Suite 7
    be installed and used in a commercial environment, free?
    -May Sun Java Calendar Server 7 be downloaded without the Communications suite?
    -Can it be run off an Apache Tomcat Server with J2SE,J2EE codebases?

    Although... at the top of this forum it says
    This is a forum for new Java developers to get acquainted with the technologies and tools associated with the Java Platform.It doesn't actually say anything about programming, not there nor in what follows. So it isn't surprising that the OP thought this was a suitable forum to ask about that server, which looks as if it might be a "tool associated with the Java platform".

  • Sun Java security problems

    Please any one tel me about Sun Java security problems
    with Desktop application

    Hi.
    If you're using SSGD 4.41, please download the Admin guide from here:
    http://docs.sun.com/app/docs/doc/820-4907
    There, at page #41 you'll find useful info concerning "Client Connections and Security Warnings".
    Hope this helps,
    Rob

  • Creating calendar problems

    Spent a few hours last night making a calendar in iPhoto only to have it crash on the month of December. Any way to find the auto save file?
    Thanks

    wolfwill:
    Welcome to the Apple Discussions. I believe the calendar info is saved in the iPhoto6.library file. If there is a temp file it may be in the same folder that the pdf files get created for uploading and printing: /private/var/tmp/folders.501/TemporaryItems/iPhoto/. If you past that in the Go->Go to folder menu option in the finder it will take you there if that iPhoto folder has been created.
    If you haven't upgraded to 6.0.1 you might do so as that's supposed to have fixed the calendar problems.

  • OS X Lion - JAVA SCRIPT PROBLEM

    I recently updated from Snow Leopard to OS X Lion. Now I seem to have a JAVA Script problem. Where do I start fixing this issue. I have checked updates etc etc but it seems to be updated. However, when I login to my web site backend, I have a problem. Any advice please?

    Would you please write some more details? explain the problem and what web site backend you use. Thanks.

  • BB10 Calendar problem SOLVED!!!

    BB10 Calendar problem SOLVED!!!
    Step 1: DO NOT do a device switch using BB Link!
    Step 2: On your old device, do a device switch using an "SD Card' - this helped me big time since it copied everything!
    Step 3: On your BB10 device, insert the old SD card, and complete the device switch using the "SD Card" option.
    Step 4: Voila! All your calendar, phone book and personal data is all transferred on to your new BB10.
    All the best!

    I had a blackberry 9780 (now a Z10)  When I go to setup on the old BB the "device switch" icon is not there.
    Is there anyway I can get that as an option on the phone so I can try what you suggest

  • 3.1 upgrade- calendar problem- error mssg interpretaion

    I just did the 3.1 upgrade and the calendar won't sync- the message is "replace the calendar on the iphone from the info tab in the iphone preferences"
    Not to be an idiot- but, I can't find "preferences" in the settings or calendar- anywhere. Can someone tell me what I am missing here????
    Thanks-

    the 4.3.1 upgrade has had many calendar problems - I'm actually surprised you've only had timing issues. Many people have lost events, seen duplicate events, and no longer receive invitations to calendared events. I have not yet heard from Apple how they plan on fixing this. It's definitely causing big problems for me and many others.

  • Migrate customer defined calendar to Sun Java Calendar

    I am planning to build a XML formated file from my in house build calendar system and use Sun Java Calendar import functionality to import the data to Sun Calendar system.
    following is an sample of an entry by XML
    <EVENT>
         <UID>0000000000000000000000000000000042dd782200002d760000024c000001b8</UID>
         <DTSTAMP>20050725T194431Z</DTSTAMP>
         <SUMMARY>Somthing</SUMMARY>
         <START>20050721T220000Z</START>
         <END>20050721T230000Z</END>
         <CREATED>20050719T220106Z</CREATED>
         <LAST-MOD>20050719T222513Z</LAST-MOD>
         <PRIORITY>5</PRIORITY>
         <SEQUENCE>0</SEQUENCE>
         <DESC>This is a dummy entry 2</DESC>
         <CLASS>PUBLIC</CLASS>
         <LOCATION>401 B</LOCATION>
         <ORGANIZER CN="cal Z (cal)" X-NSCP-ORGANIZER-UID="cal" X-S1CS-EMAIL="[email protected]">cal</ORGANIZER>
         <STATUS>CONFIRMED</STATUS>
         <TRANSP>OPAQUE</TRANSP>
         <X-NSCP-ORIGINAL-DTSTART>20050722T220000Z</X-NSCP-ORIGINAL-DTSTART>
         <X-NSCP-LANGUAGE>en</X-NSCP-LANGUAGE>
         <X-NSCP-DTSTART-TZID>America/Chicago</X-NSCP-DTSTART-TZID>
         <X-NSCP-TOMBSTONE>0</X-NSCP-TOMBSTONE>
         <X-NSCP-ONGOING>0</X-NSCP-ONGOING>
         <X-NSCP-ORGANIZER-EMAIL>[email protected]</X-NSCP-ORGANIZER-EMAIL>
         <X-NSCP-GSE-COMPONENT-STATE X-NSCP-GSE-COMMENT="PUBLISH-COMPLETED">65538</X-NSCP-GSE-COMPONENT-STATE>
    </EVENT>
    Can anybody tell me how can I get a UID?
    What's <X-NSCP-GSE-COMPONENT-STATE X-NSCP-GSE-COMMENT="PUBLISH-COMPLETED">
    What's <DTSTAMP>20050725T194431Z</DTSTAMP>
    Thanks a lot!
    Cal

    Look at RFC2446 it defnes the iCal format.
    On page 58 it states:
    the "DTSTAMP" property specifies the date/time that iCalendar object was created.
    lance

  • Java Calendar SDK Problems

    In J2SE 1.4.2, I cant seem to run the demo java application.
    Every time I do so, I get the following error as a windows prompt:
    The procedure entry point CAL_AttrValueDate could not be located in the dynamic link library ctcalcli.dll.
    After I click ok on the prompt I get this at the java output:
    java.lang.UnsatisfiedLinkError: C:\capi\java\csdkjni.dll: The specified procedure could not be found
         at java.lang.ClassLoader$NativeLibrary.load (Native Method)
         at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1560)
         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1485)
         at java.lang.Runtime.loadLibrary0(Runtime.java:788)
         at java.lang.System.loadLibrary(System.java:834)
         at oracle.calendar.sdk.Api.<clinit>(Api.java:63)
         at CalendarTest.main(CalendarTest.java:13)
    Please help me! :)

    Hi Felix,
    On Windows, make sure that BOTH the CSDK runtime libraries (normally installed in capi/lib inside your installation target directory) as well as the CSDK JNI library (normally installed in capi/java) are in your PATH environment variable before running (and not the LD_LIBRARY_PATH environment variable as indicated in the java demo's README file).
    Graham

  • Sun java calendar 6.3 to CALDAV migration problem

    Hi guys, could you help us?
    We tried to migrate users from calendar 6.3 to calendar 7U1 (formally known as calendar for CALDAV clients), but we were not successful.
    Users were located in LDAP (version 6.3.1 on Solaris 10 x64) and had values in LDAP in following format:
    dn: uid = user,dc=example,dc=com
    mail = user_name@domain
    Problem resides in following:
    1. start of migration:
    davadmin migration -a user@domain -F clifile -c
    2. in master.log (migration log) we saw
    [user_name@domain] Fetch of user preferences failed for user_name@domain -
    [user_name@domain] Migration did not complete successfully.
    Migration complete.
    3. in LDAP access log we saw, that first search with filter "mail: user_name@domain" was successful, but in following - second search we saw that uid is garbled - "uid=user@domain". User with "uid=user@domain" was not in LDAP. But after some trying we found out that the problem was in domain part. When we tried get_userprefs.wcap in browser with uid without domain part (uid=user) we got relevant information, because such entry existed in our LDAP.
    So the question is: Is there any way how to remove domain part from uid during LDAP search?
    Many thanks.
    LV.

    Hi guys, thank you very much for your answer.
    There is a typo in my previous post, in step 1, I'm sorry.
    We run migration with following command:
    davadmin migration -a user_name@domain -F clifile ..... (user is defined in format of "user_name@domain" - mail format and not in format user@domain how I wrongly wrote last time).
    Btw., when we use format user@domain ( format uid@domain) we get error which is talking about "Unknown user". This is correct because such user does not exist in our LDAP.
    When we use format user_name@domain we get error which was described in my previous post.
    Could you tell us, how to check legacy mode in our sun calendar 6.3 installation?
    Many thanks.
    LV.

  • Outlook Calendar & problem with Invitations

    Exchange calendar sync fine, but there's an interaction question or problem.
    SCENARIO:
    --Calendar entry is in Outlook, as "accepted", with this acceptance coming from me on Windows desktop.
    --Receive a Duplicate "invitation" on the iPhone.
    --On the iPhone, the event invitation shows as "maybe".
    --Don't need to accept meeting invitation....
    --Using the invitation slide option to "delete" it from the invite inbox, the entry is deleted AND IN THE CALENDAR AND ON THE EXCHANGE SERVER.
    If you want to clean out the invitation inbox, how do you do it without deleting the actual calendar entry???

    Refer to cross-post http://forum.java.sun.com/post!reply.jspa?messageID=9964809

  • Outlook connector calendar problem

    Dear All
    I having problem with outlook connector, my users are able to see each others calendar from /uwc but they are not able to browse each other calendar from outlook, I have read something in regards of aci setting in ldap directory but I have no idea where to start.
    any help is apperciated.
    Best regards
    Mo

    Refer to cross-post http://forum.java.sun.com/post!reply.jspa?messageID=9964809

Maybe you are looking for