JavaScript Date object isssue

Am I crazy or this does not work correctly in Safari 6.1.1 (7537.73.11), on Mac OS X Lion 10.7.5 (11G63).
function myFunction()
var date1 = new Date(2014, 2, 30, 1, 59);
var date2 = new Date(date1.getTime() + 120 * 1000); //add 120 seconds
alert(date1 + ' / ' + date2)
This gives output:
Sun Mar 30 2014 00:59:00 GMT+0100 (CET) / Sun Mar 30 2014 01:01:00 GMT+0100 (CET)
But that is not correct I believe. It should be (Chrome shows it correctly):
Sun Mar 30 2014 01:59:00 GMT+0100 (CET) / Sun Mar 30 2014 03:01:00 GMT+0200 (CEST)
I am in "Europe/Zagreb" timezone, and DST starts on Sun, Mar 30 2014 02:00:00 (the clock is to be moved forward to 03:00:00). According to that, chrome's display is correct.

Hi,
Probably you could also do something like this using PL/SQL dynamic content region
htp.p('<div id="chart_div" style="width: 600px; height: 300px;"></div>');
htp.p(q'|
    <script type="text/javascript">
      google.load('visualization', '1', {'packages':['motionchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Fruit');
        data.addColumn('date', 'Date');
        data.addColumn('number', 'Sales');
        data.addColumn('number', 'Expenses');
        data.addColumn('string', 'Location');
        data.addRows([
|');
FOR c1 IN (
SELECT col1, col2, col3, col4, TO_CHAR(date1,'MM/DD/YYYY') as date1
FROM my_tbl
)LOOP
  /* construct your data here */
  htp('["' || c1.col1 || '", new Date (' || c1.date1 || '), ' || c1.col2 || ', ' || c1.col3 || ', "' || c1.col3 || '"]');
END LOOP;
htp(q'| ]);
        var chart = new google.visualization.MotionChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 600, height:300});
    </script>
|');Regards,
Jari

Similar Messages

  • Javascript: data object question

    Hi, I have the following data object. Each string in the "lib" element represents a new record. I need to display each of these records in html table format so I can be able to sort on each column. How can I get each string from each element into its own row, or is there a better way to populate this data object? Thanks.
    var jsData = new Array();
    for (var i = 0; i < 4; i++)
       jsData[jsData.length] = {lib: "string1,string2,string3,string4", id: "num1,num2,num3,num4", com: "string1,string2,string3,string4"};
    }html table output should look like:
    string1 | num1 | string1
    string2 | num2 | string2
    string3 | num3 | string3
    string4 | num4 | string4

    java != javascript
    google javascript forum.

  • CRM Javascript Date Functions

    Hi all,
      I have a Javascript Date object with the datetime translated from UTC to the current user timestamp, but I need to obtain the day of the week of this datetime according to this timestamp, not according to the local time from the machine and not according
    to UTC. Can anyone help me?
    Thanks,
    David N.

    function checkEstimatedCloseDate() {
    var date = Xrm.Page.getAttribute("estimatedclosedate").getValue();
    if (date != null) {
    var today = new Date();
    var currentDate = today.getDate().toString() + "/" + (today.getMonth() + 1).toString() + "/" + today.getFullYear().toString();
    var dateWithNoTime = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate());
    if (Xrm.Page.getAttribute("estimatedclosedate").getValue() < dateWithNoTime) {
    alert("Estimated Close Date Cannot Before " + currentDate);
    Xrm.Page.getAttribute("estimatedclosedate").setValue(null);
    event.returnValue = false;
    Regards Faisal

  • Add attachments to List Item using JavaScript Client object model in SP2010

    Hi All ,
    I have created custom form for submitng data in list using javascript client object model/jquery .
    Now I want to add option to uplaod multiple attachments to that list item also .
    Is there option with client object model for uplaoding attachment.
    Thanks
    M
    Manesh G

    Can you try this and let me know
    using (SPSite _site = new SPSite(SPContext.Current.Site.Url))
        using (SPWeb _web = _site.OpenWeb())
         //Let's suppose your Item Id is 1
         int ItemId = 1;
         SPList  oList = _web.Lists["EmployeeList"];
         SPListItem  _item = oList.GetItemById(ItemId);
         if (FileUpload1.HasFile)
               _web.AllowUnsafeUpdates = true;
              Stream fs = FileUpload1.PostedFile.InputStream;
              byte[] _bytes = new byte[fs.Length];
              fs.Position= 0;
              fs.Read(_bytes, 0, (int)fs.Length);
              fs.Close();
              fs.Dispose();
              _item.Attachments.Add(FileUpload1.PostedFile.FileName, _bytes);
              _item.Update();
              _web.AllowUnsafeUpdates = false;

  • Omni portlet - javascript - date field problem

    I want to manipulate a database date type field with javascript in omniportlet layout.
    In the source tab of omniportlet I use the SQL: (it's very simple for example)
    select id, to_char(enddate, 'DD/MM/YYYY HH24:MI') edate, enddate
    from tlh.auctionsession
    where id = 1
    In the layout tab (HTML form). I write this javascript code in Repeating Section: (it's very simple for example)
    <script type="text/javascript">
    document.write(##EDATE##);
    </script>
    It's not woking. Anytime I use the ##EDATE## or ##ENDDATE## in my javascript code, It's not working.
    If I put ##EDATE## of ##ENDDATE## in the HTML's body, it's display well.
    I am really mad with it.
    Do you have any idea? Please help me with it. Thank you very much.
    Sorry for my bad English.

    // custom vaildation scirpt for entered date being today or a future date;
    // date format for the field;
    var cDateFormat = "mm/dd/yyyy";
    // convert the entered value to a date objecta;
    var oEntered = util.scand(cDateFormat, event.value);
    // strip down to just the year, month and day
    oEntered.setFullYear(oEntered.getFullYear(), oEntered.getMonth(), oEntered.getDate());
    // convert todays date to a date object;
    oToday = util.scand(cDateFormat, util.printd(cDateFormat, new Date()));
    // strip down to just the year, month and day
    oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(), oToday.getDate());
    // compare the date values
    if(oEntered.getTime() < oToday.getTime()) {
    // error message date before today's date
    app.alert("Date must be today's date or a futuer date!", 1, 0);
    // set return code to error status;
    event.rc = false;
    // validation is assumed to be true unless the event return code value is false;
    // end custom validation script;

  • Delete a row from a data object using an AQ-driven EMS

    Hello, technetwork.
    I need to show the contents of a table that changes frequently (inserts, updates and deletes) at ORDBMS 10g in my BAM dashboard.
    What i have done is:
    - Create two different queue tables, queues.
    - Create two triggers: one for "AFTER insert or UPDATE" and the other for "BEFORE DELETE".
    - Create two EMS, one configured to Upsert operations and the other to Delete.
    - The Upsert EMS works, but the Delete EMS does not.
    - Both EMS Metrics say that they work fine and commit the messages i send to the ADC.
    - Testing showed records are populated and updated in the ADC but never deleted.
    There is a detailed user case for "Creating an EMS Against Oracle Streams AQ JMS Provider" in the Fusion Midleware Developer's Guide for SOA Suite, but it deals only with Upserts. I am using the last versions of SOA suite and Weblogic. The official support has no information either.
    I hope writing a web service client isn't the only way to delete a row from a data object. Am i missing something? Any help will be much appreciated.
    My EMS config:
    Initial Context Factory: weblogic.jndi.WLInitialContextFactory.
    JNDI Service Provider URL: t3://<spam>:80.
    Topic/Queue Connection Factory Name: jms/BAMAQTopicCF.
    Topic/Queue Name: jms/ProdGlobalBAMD_flx.
    JNDI Username: .
    JNDI Password: .
    JMS Message Type: TextMessage.
    Durable Subscriber Name (Optional): BAM_ProdGlobalBAMD.
    Message Selector (Optional): .
    Data Object Name: /bam/ProdGlobalBAM_flx.
    Operation: Delete.
    Batching: No.
    Transaction: No.
    Start when BAM Server starts: No.
    JMS Username (Optional): .
    JMS Password (Optional): .
    XML Formatting
    Pre-Processing
    Message Specification
    Message Element Name: row
    Column Value
    Element Tag
    Attribute
    Source to Data Object Field Mapping
    Key Tag name Data Object Field
    . BARCODE. BarCode.
    Added my EMS config

    Ram_J2EE_JSF wrote:
    How to accomplish this using JavaScript?Using Javascript? Well, you know, Javascript runs at the client side and intercepts on the HTML DOM tree only. The JSF code is completely irrelevant. Open your JSF page in your favourite webbrowser and view the generated HTML source. Finally just base your Javascript function on it.

  • _system.date() as a date object?

    My system reports back _system.date() as mm/dd/yy which I
    could easily parse but I understand that the system date format is
    dependent on the user's OS, preference settings, language, mood ;-)
    There’s got to be an easy way to get the system date as a
    date object. I saw in an earlier post that OpenSpark has written a
    bunch of cool calendar math routines but I need to start with
    today’s date as a date object.

    I use JavaScript syntax exclusively anymore, so I use the
    JavaScript syntax Date object. It’s fairly robust and
    x-platform. This is much like ensamblador’s use of the Flash
    Date object. The Flash Date object and the JavaScript syntax Date
    object are both implementations of ECMAScript 262, so it’s
    one of those “six of one half dozen of the other”
    situations. If you are scripting in Lingo then you would need to
    create a Flash object and then instantiate a Date object in it. If
    you’re scripting in JavaScript syntax then just use its
    native Date object. When using the Date object you gotta remember
    that the day of the week – dateObject.getDay() - and the
    month - dateObject.getMonth() – are zero indexed... 0 =
    Sunday, 0 = January etc. When I have to display day names or month
    names I use arrays to store the names I want to display. Also,
    hours are in 24 hour (military) time, so dateObject.getHours()
    would return 16 at 4:27 pm. You can account for that by subtracting
    12 from the returned Hours value if it is greater than 12.
    function exitFrame(me)
    var dObj = new Date();
    var theHour = dObj.getHours();
    var apendTime = " am";
    var dayArray = new
    Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var dateArray = new
    Array("January","February","March","April","May","June","July","August","September","Octo ber","November","December");
    var iText = member("infoText");
    ///// show the date textually
    iText.text = dayArray[dObj.getDay()] + " " +
    dateArray[dObj.getMonth()] + " " + dObj.getDate() + ", " +
    dObj.getFullYear();
    ///// mm/dd/yyyy format
    iText.text += "\n" + (dObj.getMonth() + 1) + "/" +
    dObj.getDate() + "/" + dObj.getFullYear();
    ///// show the time like a digital clock
    // 24 hour (military) time
    iText.text += "\n" + theHour + dObj.getMinutes() + ":" +
    dObj.getSeconds();
    // civilian time
    if (theHour > 12)
    iText.text += "\n" + (theHour - 12);
    apendTime = " pm";
    } else {
    iText.text += "\n" + theHour;
    apendTime = " am";
    // the minutes and seconds
    iText.text += ":" + dObj.getMinutes() + ":" +
    dObj.getSeconds() + apendTime;
    _movie.go(_movie.frame);
    }

  • Open Data Object -  Open File attachment within pdf document

    I am trying to build a script which will open file attachments embedded in a pdf document.
    I have used the following javascript to list all embedded files within a document so I can retrieve the name
    var d = this.dataObjects;
    for (var i = 0; i < d.length; i++)
    console.println("Data Object[" + i + "]=" + d[i].name);
    The console reported:
    Data Object[0]=MTP-300-X-1210_A.pdf
    Data Object[1]=MTP-300-X-1240_A.pdf
    I then used the following script to open the file     
    this.openDataObject("MTP-300-X-1210_A.pdf");
    Console reports back as follows and does not open the file:
    [object Doc]
    Can anyone please offer assistance in how to open an embedded pdf attachment within a document?
    Many thanks!

    Hi George,
    I have used the same method app.openDoc to open attachments using a path associated with my computer.  However, as you know, the method does not work if the pdf containing the attachment is located on a different computer.  The app.openDoc method throws an error becuase the path is not valid.
    I am trying to get the following code to work with no success:
    var cFilePath = "|" + this.path + "|U:photo.pdf"';   // photo.pdf is the attachment
    app.openDoc ({cPath: cFilePath});
    The debugger throws an error.
    However, if I take the content of the variable cFilepath and instert it as an argument within cPath parameter as a string literal, the app.openDoc method returns the docObject.
    What's going on here?  shouldn't the variable cFilePath work?  Or do I need to specify a data type for the variable?  Any thoughts would be helpful.  I am using Windows 7, Adobe Acrobat X Standard.

  • Problem with childs nodes and automatic key mapping in a Data Object

    Hi experts!
    I'm doing the service order tutorial from the mobile help at [this link|http://help.sap.com/saphelp_nwmobile71/helpdata/en/21/9b5b924c3b434fba4767731794b029/frameset.htm] and I have a problem...
    In the topic "Modeling the Equipment Data Object", says you have to mark the "Automatic Key Mapping" checkbox. So when I had to create a third child node ( the location node ) the system raised an exception with the message "Deselect automatic key mapping flag for more than two-level nodes". I'm trying deselecting the flag and creating the location node, but when I want mark again the automatic key mapping flag, this is disabled.
    What can I do to solve this and create the three child nodes with the flag marked? It's a configuration thing?
    Any help it's very welcome. Thanks in advance.
    Best regards,
    Simon.

    The thing is: Its not allowed to use automatic keymapping if you have more than two levels. This is why the message showed up, and this is why its been disabled.
    What automatic keymapping does: Figures out automatically which child node belongs to which parent (by guessing from the field name and type, which fields in the child correspond to which key fields of the parent).
    On three levels, this becomes more complicated => Its disabled.
    How to do keymapping yourself instead of having the DOE do it automatically: Do 'Explicit keymapping' from each child to its parent. Explicit keymapping is done by clicking on the corresponding menu button in the child node. Here you need to associate child node fields (they need not be key fields of the child, but they are allowed to be that as well) to each of its parent nodes key fields (so that each child can be associated to its parent).
    Cheers

  • Error while activating Data object in DOE workbench

    Hi all,
    I created a Data Object and when I try to activate  that DO it is showing an error as below.
    Mobile Java client attributes not maintained.
    Please give some clue to resolve this.
    Thanks and Regards,
    Rajesh.A

    Hi Rajesh,
    I believe you had created an SWCV that is enabled for Backward Compatibility 'Uses NW04/NW04s MI application' and created a Data Object in this SWCV. Ideally, when the SWCV is enabled for Backward Compatibility, the Data Objects should be created by importing the text file as Data Objects from a MI 7.0 server. Since you have not done that way, you are getting this error.
    I would suggest that you create a new SWCV and do not check the option 'Uses NW04/NW04s MI application'. Now create the Data Object again and try to activate it and you should be able to activate it.
    Best regards,
    Vinodh

  • Unable to delete master data line items - Master data object CCHIUSRAM

    Hello
    We have an issue with the Master data Object CCHIUSRAM - CC Hier User Auth Maintenance. It has only master data and no texts no hierarchy. It is not time-dependent. It has /BIC/PCCHIUSRAM, /BIC/SCCHIUSRAM as database table only. This master data is not being used in any infoproviders.
    In development client we are able to delete the line items of the Master data along with entering line items. RSRV check gives green for all checks.
    In Test / Production client we are not able to delete the line items of the Master data. We are only able to enter master data lines and if we change any item then it creates another entry in the table.
    Tried SE14 & RSDMD_DEL_MASTER_DATA - both does not help.
    Did ST05 trace, could not find something concrete.
    If any one has faced such an issue with any master data item then a response is much appreciated. It has become a bottleneck for us.
    Many Thanks in advance
    Pradip Parmar

    Thanks for the response.
    I can do this in EBD, but it is working fine in EBD. I cannot do this activity in EBP / EBT as the systems are closed and I cannot activate directly in EBT / EBP.
    Besides, I have recently transported active versions of the object in EBT / EBP all again twice to see if it changes anything.
    My guess is that, there is something stupid may be I am missing somewhere.
    Any help is much appreciated.
    Thanks

  • Message class as result data object

    hello brf+ users,
    is it possible to use as Result data object in a Case expression a message from a custom message class?
    thanks
    danilo

    thanks Carsten,
    my requirement can be simplified in
    IF FISCAL CODE
    equals to " " then "001" ENTRY MISSING is returned
    otherwise "000" check ok is returned.
    where 000,001 are domain values of an element (MESSAGE RESULT).
    can i use the message class as result? is there a way to anchor the result to the message class?
    thanks
    danilo

  • How do I reference the data object in a DataGrid to show an image correctly in Acrobat?

    I'm creating an inferface for an Acrobat application  and I'm having a issue with displaying an image in a grid.  When I hard code the source="statusNONE.png" it works as intended (with an image, not the image associated with each grid item), however, when I try to use the source="{data.@icon}" to reference the dataProvider (XMLListCollection) I get nothing.  Not a broken image or anything.  I think I may just not be referencing the XMLListCollection correctly, otherwise I don't know why it would work with hard coding vs. fetching the string from the XML.
    //Application Header (Flex 4.5)
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                                     xmlns:s="library://ns.adobe.com/flex/spark"
                                     xmlns:mx="library://ns.adobe.com/flex/mx"
                                     width="100%" height="100%" creationComplete="eaton_creationCompleteHandler(event)"
                                     currentState="Review">
    //Sample of XML that gets used as basis for XMLListCollection
    <Annots>
         <Annot name='TEST' index='14' feedback='' canConstruct='0' icon='statusNONE.png'/>
    </Annots>
    //creation of the XMLListCollection from String
    [Bindable] protected var fullXML:XML;
    [Bindable] protected var fullXMLCol:XMLListCollection;
    protected function loadXML(xmlString:String):void
          fullXML = new XML(xmlString);
         var fullXMLList:XMLList = fullXML.children();
          fullXMLCol = new XMLListCollection(fullXMLList);
    //DataGrid
    <s:DataGrid left="0" top="0" bottom="0" width="142" dataProvider="{fullXMLCol}"
                                            requestedRowCount="4" rowHeight="30"
                                            top.Confirm="87">
                        <s:columns>
                                  <s:ArrayList>
                                            <s:GridColumn dataField="@name" headerText="Annotations"></s:GridColumn>
                                            <s:GridColumn headerText="status" width="30" >
                                                      <s:itemRenderer>
                                                                <fx:Component>
                                                                          <s:GridItemRenderer>
                                                                                    <s:Image width="30" height="30" source="{data.@icon}"/> //THIS IS THE PART THAT SEEMS TO BE GIVNG ME TROUBLE!
                                                                          </s:GridItemRenderer>
                                                                </fx:Component>
                                                      </s:itemRenderer>
                                            </s:GridColumn>
                                  </s:ArrayList>
                        </s:columns>
                        <s:typicalItem>
                                  <fx:Object dataField1="Sample Data" dataField2="Sample Data" dataField3="Sample Data"></fx:Object>
                        </s:typicalItem>
              </s:DataGrid>
    Additional information.  I'm using the resources tab for the flash embedding in Acrobat for my images. This works when I am hard coding the file name string works for the source without having to add a full path, the images are not technically bundled into the swf.   I just don't understand why using the data object to get that same string would show different results.
    tl;dr: GridItemRenderer works to show images when hard coded but not when using {data}.
    UPDATE: Figured it out, needed to add a toString() to the data.@icon.   I had assumed it was a string being handed over, I assumed wrong.

    Probably because data.@icon isn't a String, it is an XMLList, and source property is an Object not a String so the runtime doesn't automatically convert it.
      Try [email protected]()

  • Adding new Data Object while migrating from MI 2.5 to NM7.1

    Dear All,
          We have a custom MI 2.5 application which we need to migrate to 7.1. While migration, we want to add a newly created data object also in migrated application. But when I try to import MBO model, it is not letting me import new data object. The import finishes successfully. But changes in merepmeta.xml are not done. It creates a file with back up of existing merepmeta.xml i.e. merepmeta.xml.bak and create new merepmeta.xml but it is blank. Am I missing something???
           When I import MBO only with existing data objects (syncbos), it is allowing me perfectly. It is changing the merepmeta.xml accordingly as well without creating backup.
    Thanks in advance,
    Saptak Kulkarni.

    Dear Arjun,
         To answer your questions, previously all the SyncBOs were downloaded independently taking username as the import parameter in getList. (Default values). Yes we can provide the same with 7.1 but we wanted to have some sorts of associations between all SyncBOs.
         So first of all, we changed all the BAPI wrappers of old SyncBOs to download all the data independent of user. Now we created new Data Object to only download user specific data. We associated all other Data Objects on this DO. Created a rule for this data object to only download the sync user instance. We were expecting that whenever a user syncs, a single instance of new user data object will get downloaded and subsequently all other data objects having relationship on user will get downloaded. I hope this is not much confusing.
          Now while we import the MBO model, if we don't import new user data object, then also other data object instance get downloaded and fortunately properly filtered. We don't receive any kind of error over here.
          The new data object is not used anywhere in the application. The associations are in new data object and not in the older one. New data object is the leading one wherein others follow.
          Not a single instance is getting dropped for other Data Objects.
          The xml is blank only when we try to import the new Data Object and correctly it gives an error as expected when I try to deploy the application.
    Thanks in advance,
    Saptak.

  • I made a new Date object

    See, here's the thing with dates in java, the way i see it. We used to have Date, but Date wasn't international so we got Calendar. But some things, like SimpleDateFormat, still expect java.util.Date. java.sql.Date is out there somewhere, too. None of them have direct support for date differences (i.e. dateA - dateB = 8 days, or whatever). Now you're probably reading this thinking "Java supports all of this" and you're right. Calendar has a getTime method that returns a Date, and i can just pass THAT to SimpleDateFormat. With a little math, getTimeInMillis can be used to find the difference in two Calendars. But i got to thinking, "There should only be one Date object i need to think about," and since i don't ever have enough to do at work i put one together. I don't know if any of you are going to care enough to use it, mostly i'm just looking for advice on features i should add to it, inefficiencies in the design, stuff that's hard to understand, or whatever.
    This is it:
    *This catastrophe brought to you by SrA Meyerin.
    *Proximo Satis pro administatio.
    package awesomedate;
    //The following are imported for the toFormattedString(), toUtilDate(), toSQLDate, and toCalendar() methods, respectively.
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import java.sql.*;
    import java.util.TimeZone;
    *This class is designed to be the ultimate date object. It stores dates accurate to the millisecond, has the ability to do date
    *arithmetic (adding/subtracting days/months/whatever), date comparison, and date formatting. Also it can, at will, be used as any
    *of the other date objects in the standard java API.
    public class AwesomeDate
         *Milliseconds from the epoch. This field is where everything starts.
        private long millis;
         * The current year. This is the only aspect of the current date that is stored in addition to the milliseconds. Everything else
         * is calculated as needed.
        private int year;
        //The following six variables are fairly self explanatory. I'll explain them anyway.
         *Milliseconds in one non-leap year. This can be passed to the "adjustDate()" method
         * but mostly it is used to make my code more readable.
        public final static long MILLIS_IN_YEAR = 31536000000L;
         *Milliseconds in one leap year. This can be passed to the "adjustDate()" method
         * but mostly it is used to make my code more readable.
        public static final long MILLIS_IN_LEAP_YEAR = 31622400000L;
         *Milliseconds in one day. This can be passed to the "adjustDate()" method
         * but mostly it is used to make my code more readable.
        public static final long MILLIS_IN_DAY = 86400000;
         *Milliseconds in one hour. This can be passed to the "adjustDate()" method
         * but mostly it is used to make my code more readable.
        public static final long MILLIS_IN_HOUR = 3600000;
         *Milliseconds in one minute. This can be passed to the "adjustDate()" method
         * but mostly it is used to make my code more readable.
        public static final long MILLIS_IN_MINUTE = 60000;
         *Milliseconds in one second. This can be passed to the "adjustDate()" method
         * but mostly it is used to make my code more readable.
        public static final long MILLIS_IN_SECOND = 1000;
         *The number of days in each month.
        private int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
         *The timezone offset. GMT is 0, and the default, however, CST (where i live), is -6.
        private int timeZoneOffset = -6;
         *As the name would indicate, this is the number of milliseconds beyond 00:00 of jan 1 of the current year.
        private long millisAfterYear;
         *Basic constructor. Defaults to the current date and time. Works on Greenwich Mean Time, so it may seem off. To avoid this, multiply
         *add your time zone offset * MILLIS_IN_HOUR to the time in milliseconds.
        public AwesomeDate()
            setTimeInMillis(System.currentTimeMillis());
         *Fairly simple constructor. Sets time to the the number of milliseconds passed past the epoch.
        public AwesomeDate(long millis)
            setTimeInMillis(millis);
         *This constructor sets the date to the year/month/day passed.
        public AwesomeDate(int year, int month, int day)
            setDate(year, month, day);
         *This constructor sets the date time to the year/month/day/minute/hour/second passed.
        public AwesomeDate(int year, int month, int day, int hour, int minute, int second)
            setDate(year, month, day, hour, minute, second);
         *When you have the number of milliseconds, the first thing you must calculate is year. Because the number of milliseconds in a
         *year may vary, this is also the most difficult to calculate. This is the method that does it, though.
        private void setYearAfter1970()
            //I don't want to alter the actual number of milliseconds, so i make this variable and perform calculations on it.
            long theseMillis = this.millis;
            //Start at 1970 (the epoch) and work from there.
            year = 1970;
            long nextYear = MILLIS_IN_YEAR;
            //In this loop i subtract the number of millis in whatever year. The condition is if i have enough millis to make it through
                //another year.
            while (theseMillis >= nextYear)
                if (isLeapYear(year))
                    theseMillis = theseMillis - MILLIS_IN_LEAP_YEAR;
                    nextYear = MILLIS_IN_YEAR;
                else
                    theseMillis = theseMillis - MILLIS_IN_YEAR;
                    if (isLeapYear(year + 1))
                        nextYear = MILLIS_IN_LEAP_YEAR;
                year++;
            millisAfterYear = theseMillis;
            this.year = year;
         *Calculating the year from before 1970 must be done differently. It's pretty much just inverted.
        private void setYearBefore1970()
            long theseMillis = this.millis;
            year = 1970;
            long nextYear = MILLIS_IN_YEAR;
            while (theseMillis <= 0)
                if (isLeapYear(year))
                    theseMillis = theseMillis + MILLIS_IN_LEAP_YEAR;
                    nextYear = MILLIS_IN_YEAR;
                else
                    theseMillis = theseMillis + MILLIS_IN_YEAR;
                    if (isLeapYear(year - 1))
                        nextYear = MILLIS_IN_LEAP_YEAR;
                year--;
            millisAfterYear = theseMillis * -1;
            this.year = year;
         *Just what it sounds like. Pass it the number of milliseconds past the epoch and it will calculate the date based on that.
        public void setTimeInMillis(long millis)
            this.millis = millis;
            if (millis >= 0)
                setYearAfter1970();
            else
                setYearBefore1970();
         *Returns the number of milliseconds from the epoch.
        public long getTimeInMillis()
            return this.millis;
         *Returns the current year.
        public int getYear()
            return this.year;
         *Sets the date to 00:00 of Jan 1 of the passed year.
        public void setYear(int year)
            this.year = year;
            long theseMillis = 0;
            if (year > 1970)
                //Kind of like setYearAfter1970 method, except it's adding instead of subtracting. So actually it's the opposite.
                for (int cntr = 1970; cntr < this.year; cntr++)
                    if (isLeapYear(cntr))
                        theseMillis = theseMillis + MILLIS_IN_LEAP_YEAR;
                    else
                        theseMillis = theseMillis + MILLIS_IN_YEAR;
            else
                for (int cntr = 1970; cntr > this.year; cntr--)
                    if (isLeapYear(cntr))
                        theseMillis = theseMillis - MILLIS_IN_LEAP_YEAR;
                    else
                        theseMillis = theseMillis - MILLIS_IN_YEAR;
            //On a leap year there are 29 days in February. If not, there's 28.
            if (isLeapYear(year))
                daysInMonth[1] = 29;
            else
                daysInMonth[1] = 28;
            //This variable helps me calculate denominations of time that are below year.
            millisAfterYear = 0;
            setTimeInMillis(theseMillis);
         *Sets the month to the one that you passed, 0 being January and 11 being December.
        public void setMonth(int month)
            if (month < 0 || month > 11)
                throw new ArrayIndexOutOfBoundsException(month);
            long theseMillis = getTimeInMillis();
            int days = 0;
            setYear(this.year);
            if (getTimeInMillis() > 0)
                theseMillis = theseMillis - getTimeInMillis();
            else
                theseMillis = theseMillis + getTimeInMillis();
            for (int cntr = 0; cntr < month; cntr++)
                days = days + daysInMonth[cntr];
            millisAfterYear = days * MILLIS_IN_DAY + 1;
            setTimeInMillis(getTimeInMillis() + millisAfterYear);
         *Returns the month stored in this object. With this object 0 represents January and 11 represents December.
        public int getMonth()
            long theseMillis = millisAfterYear;
            int cntr = 0;
            while (theseMillis > (MILLIS_IN_DAY * daysInMonth[cntr]))
                theseMillis = theseMillis - MILLIS_IN_DAY * daysInMonth[cntr];
                cntr++;
            return cntr;
         *Set the day of month to the one passed.
        public void setDayOfMonth(int day)
            if (day < 1 || day > daysInMonth[getMonth()])
                throw new ArrayIndexOutOfBoundsException(day);
            setMonth(getMonth());
            //Internally, this actually works starting at zero, however to anyone using this class it appears to start at 1. Therefore
                //i must subtract one here.
            long addMillis = MILLIS_IN_DAY * (day - 1);
            millisAfterYear = millisAfterYear + addMillis;
            setTimeInMillis(getTimeInMillis() + addMillis + 1);
         *Returns the day of month.
        public int getDayOfMonth()
            int days = (int)(millisAfterYear / MILLIS_IN_DAY);
            int cntr = 0;
            while (days >= daysInMonth[cntr])
                days = days - daysInMonth[cntr];
                cntr++;
            //Internally this class stores dates starting at zero, but i want it to look like it starts at 1.
            return days + 1;
         *Sets the time to the currently selected day at the passed hour on the hour. uses 24 hour clock.
        public void setHour(int hour)
            if (hour < 0 || hour > 23)
                throw new ArrayIndexOutOfBoundsException(hour);
            setDayOfMonth(getDayOfMonth());
            long addMillis = MILLIS_IN_HOUR * hour;
            millisAfterYear = millisAfterYear + addMillis;
            setTimeInMillis(getTimeInMillis() + addMillis);
         *Returns the hour (but not how many minutes past the hour).
        public int getHour()
            long millisAfterDay = millisAfterYear % MILLIS_IN_DAY;
            return (int)(millisAfterDay / MILLIS_IN_HOUR);
         *Set the minutes past the hour. Works 0-59.
        public void setMinute(int minute)
            if (minute < 0 || minute > 59)
                throw new ArrayIndexOutOfBoundsException(minute);
            setHour(getHour());
            long addMillis = MILLIS_IN_MINUTE * minute;
            millisAfterYear = millisAfterYear + addMillis;
            setTimeInMillis(getTimeInMillis() + addMillis);
         *Returns the minutes past the hour, 0-59.
        public int getMinute()
            long millisAfterHour = millisAfterYear % MILLIS_IN_HOUR;
            return (int)(millisAfterHour / MILLIS_IN_MINUTE);
         *Sets the seconds past the minute, 0-59.
        public void setSecond(int second)
            if (second < 0 || second > 59)
                throw new ArrayIndexOutOfBoundsException(second);
            setMinute(getMinute());
            long addMillis = MILLIS_IN_SECOND * second;
            millisAfterYear = millisAfterYear + addMillis;
            setTimeInMillis(getTimeInMillis() + addMillis);
         *Returns the seconds past the minute, 0-59.
        public int getSecond()
            long millisAfterMinute = millisAfterYear % MILLIS_IN_MINUTE;
            return (int)(millisAfterMinute / MILLIS_IN_SECOND);
         *The more commonly seen set method of other date objects. Sets the date/time to 00:00 of the year/month/day passed. Convenience method
         *for setDate(int year, int month, int day, int hour, int minute, int second).
        public void setDate(int year, int month, int day)
            setDate(year, month, day, 0 , 0 , 0);
         *Sets every date/time field.
        public void setDate(int year, int month, int day, int hour, int minute, int second)
            setYear(year);
            setMonth(month);
            setDayOfMonth(day);
            setHour(hour);
            setMinute(minute);
            setSecond(second);
         *Returns yes if the stored date is a leap year. A leap year is every year that is divisible by four unless it is divisible by 100
         *unless it is also divisible by 400.
        public boolean isLeapYear()
            return isLeapYear(this.year);
         *For internal use. Returns if the passed year meets the criteria for a leap year.
        private boolean isLeapYear(int year)
            boolean leapYear = false;
            if (year % 4 == 0)
                if (year % 100 != 0)
                    leapYear = true;
                else if (year % 400 == 0)
                    leapYear = true;
            return leapYear;
         *Returns the difference in milliseconds between the time stored in this object and the millis passed to this method.
        public long getDifferenceInMillis(long millis)
            return getTimeInMillis() - millis;
         *Returns the difference in milliseconds between this date and the date passed to this method.
        public long getDifferenceInMillis(AwesomeDate otherDate)
            return getDifferenceInMillis(otherDate.getTimeInMillis());
         *Designed to be a wrapper method for the getDifferenceInMillis method. This method changes millis into years/days/whatever. Pass
         *the number of milliseconds you have to convert in the first parameter. The second parameter should be the type of denomination you
         *want (year, day, whatever). Use the MILLIS_IN_* fields associated with this object. Also bear in mind when workin with years that
         *some years are leap years, so in extreme cases of differences of 365+ years you may gain/lose a year.
        public static int toGreaterDenom(long millis, long denom)
            return (int)(millis / denom);
         * The first argument is how many of whatever (days, months, years, etc.) to add (use negative numbers to subtract). For the second
         * argument pass one of the MILLIS_IN_* fields. Thus, to add two hours would be
         * <code>
         *      AwesomeDate.adjustDate(2, AwesomeDate.MILLIS_IN_HOUR);
         * </code>
        public void adjustDate(int amount, long typeMillis)
            setTimeInMillis(this.millis + amount * typeMillis);
         *Returns an object of type java.util.Date set to the date/time stored here.
        public java.util.Date toUtilDate()
            long offset = TimeZone.getDefault().getRawOffset();
            return new java.util.Date(getTimeInMillis() +  -1 * offset);
    //        return new java.util.Date(getTimeInMillis());
         *Returns an object of type GregorianCalendar set to the date/time stored here.
        public GregorianCalendar toGregorianCalendar()
            long offset = TimeZone.getDefault().getRawOffset();
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(getTimeInMillis() - offset);
            return cal;
         *Returns an object of type java.sql.Date set to the date/time stored here.
        public java.sql.Date toSQLDate()
            long offset = TimeZone.getDefault().getRawOffset();
            return new java.sql.Date(getTimeInMillis() - offset);
        /** Format the date  using the string that you pass. Works just like the SimpleDateFormat object. Infact, it uses one! Heres
         *how it works:
         *Letter  Date or Time Component  Presentation  Examples  <br>
         *G  Era designator  Text  AD  <br>
         *y  Year  Year  1996; 96  <br>
         *M  Month in year  Month  July; Jul; 07<br> 
         *w  Week in year  Number  27  <br>
         *W  Week in month  Number  2  <br>
         *D  Day in year  Number  189  <br>
         *d  Day in month  Number  10  <br>
         *F  Day of week in month  Number  2<br> 
         *E  Day in week  Text  Tuesday; Tue  <br>
         *a  Am/pm marker  Text  PM  <br>
         *H  Hour in day (0-23)  Number  0<br> 
         *k  Hour in day (1-24)  Number  24  <br>
         *K  Hour in am/pm (0-11)  Number  0  <br>
         *h  Hour in am/pm (1-12)  Number  12  <br>
         *m  Minute in hour  Number  30  <br>
         *s  Second in minute  Number  55  <br>
         *S  Millisecond  Number  978  <br>
         *z  Time zone  General time zone  Pacific Standard Time; PST; GMT-08:00<br> 
         *Z  Time zone  RFC 822 time zone  -0800  <br>
        public String toFormattedString(String format)
            SimpleDateFormat formattage = new SimpleDateFormat(format);
            return formattage.format(toUtilDate());
         *I overrode the toString method. Now it tells everyone how awesome my AwesomeDate is.
        public String toString()
            String output = "John's Awesome Date!";
            output = output + " Millis: " + getTimeInMillis();
            output = output + " Year: " + getYear();
            output = output + " Month: " + getMonth();
            output = output + " Date: " + getDayOfMonth();
            output = output + " Time: ";
            if (getHour() < 10)
                output = output + "0" + getHour();
            else
                output = output + getHour();
            if (getMinute() < 10)
                output = output + "0" + getMinute();
            else
                output = output + getMinute();
            output = output + " Seconds: " + getSecond();
            return output;
        public static void main(String[] psvm)
            AwesomeDate blah = new AwesomeDate();
            GregorianCalendar blah1 = new GregorianCalendar();
            GregorianCalendar blah2 = new GregorianCalendar();
    }

    The reason Callendar is so complicated is that it is trying to solve a very complicated problem.
    You don't appear to support leap seconds (of which there can be upto 2 in any time interval)
    http://www.timeanddate.com/time/leapseconds.html
    Some of your code will not work for large dates very well (seems to iterate over the years). Try using your date class for astronomical or geological calculations. them big numbers will make your code slow at the moment.
    You don't seem to support timezones or transitory offsets (BST vs GMT). You most definately don't handle changes to timezone offsets that have occured in the past or historical daylight savings time offsets (they have not always been the same)
    The difference between two calendars is a "duration" a duration means nothing unless it is applied to a caledar/date (although you may be able to get away with it if the duration is always stored in millis)

Maybe you are looking for

  • CMS for Dreamweaver designed site

    HI, I designed an 8 page website for a friend with dreamweaver cs3 and he would like to access the pages himself to make text changes from his own PC. Is there a CMS that he can download and use to change text and images on a website desinged with CS

  • Can not add domain name Error Protected word / inappropriate language

    Can not add domain name Error Protected word /  inappropriate language         Provide your Domain name : pragatiassociates.com Nature of Services provided: It located in India, Punjab. Its a new firm which will be focus on supplying products to Educ

  • PrintSetting, ColorManagement, PrintOption, ExtensionSetting, are blocked

    PrintSetting, ColorManagement, PrintOption, ExtensionSetting, are blocked in Aperture. I noticed in Word i can use these settings for the paper i am useing and Aperture will not hold these settings. I have an Epson R1800 and have downloaded the lates

  • Maya 2009 French keyboard problem (MBP)

    Hey everyone, I was just wondering if anyone has any problems with (French in my case) keyboard shortcuts with Maya on a Macbookpro (early 2008). Its just ****. I don't have access to the numerical keys (1,2,3,...), and it seems that I can't reassign

  • Unable to access CC assets and VERY frustrated with support

    I just spent a fruitless hour trying to discover why I am unable to access my assets on the Creative Cloud. CC acts as if my membership isn't current, in that I see a folder of mine, but when I click on it, it disappears. After an hour with support I