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)

Similar Messages

  • 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.

  • How to get the currrent month and year from a new date object

    If I create a new Date object as "d",
    java.util.Date d = new java.util.Date();how can I format the date to get the current Month as 'Jan' and the current year as '2008'. So if I have something like d.getMonth() gets the current month as 'Oct' and d.getYear() gets '2008'
    Thanks,
    Zub

    [Read the flamin' manual you must. Hmm.|http://en.wikipedia.org/wiki/RTFM]
    ~~ Yoda.
    Well no actually, he didn't say that, but he should have.
    Cheers. Keith.
    PS: Don't say that to a 7 foot pissedOff wookie when he's got his head stuck in a smoking hyperdrive, and you're being chased by a S-class battle cruiser... Ask Yoda how he got to be so short.
    PPS: It is the SimpleDateFormat you seek ;-)
    Edited by: corlettk on 14/10/2008 22:37 ~~ Also far to slow... but funny.

  • Coverting Date.toString() back to a new Date object

    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#toString()
    After reading this, I am able to see the output format:
    dow mon dd hh:mm:ss zzz yyyy
    However, my questions is, what if you want to convert this String back into a new Date object later? After reviewing SimpleDateFormatter and other related classes, I find nowhere there is a linked parsing that allows this to be easily coverted back into a new Date object at runtime.
    Am I wrong?
    Thanks.

    Yup, the problem is that I do not have a reference to
    the original string. Is there a simple direct way to
    do this?Wait, I misread this. The original string?
    If you have a Date and get a String out of it, and you later want the original Date, then it's generally better to restructure your app to preserve the original Date. If for some reason that isn't an option (although often things are options when you don't think they are), then you can use SimpleDateFormat to produce a new Date object who value matches the date that the String represents.

  • Data type and Data object

    Hi Friends,
            What is the difference between Data type and Data object?
    Best Regards,
    VRV Singh

    hi
    good
    Each ABAP program define its own data types using the statement.
    TYPES dtype TYPE type ...
    and declare its own variables or instance attributes of classes using the statement
    DATA var {TYPE type} ...
    Within the program or a class, you can also define local data types and variables within procedures. Local variables in procedures obscure identically-named variables in the main program or class.
    When creating data types and data objects, there are a number of naming convention that also apply for other local program definitions, such as procedures. These are described in detail in the keyword documentation.
    The Additions TYPE and LIKE
    The additions TYPE type and LIKE dobj are used in various ABAP statements. The additions can have various meanings, depending on the syntax and context.
    ·        Definition of local types in a program
    ·        Declaration of data objects
    ·        Dynamic creation of data objects
    ·        Specification of the type of formal parameters in subroutines
    ·        Specification of the type of formal parameters in methods
    ·        Specification of the type of field symbols
    Constructing New Data Types
    The TYPE addition allows you to construct new data types in the TYPES, DATA; CONSTANTS; and STATICSstatements. In the TYPES statement, these are local data types in the program. In the other statements, they are attributes of new data objects, meaning that the newly defined data types are not free-standing. Rather, they are linked to database objects.This means that you can refer to them using the LIKEaddition, but not using TYPE.
    To construct new data types, the addition TYPE can be used with the following type constructors:
    ·        Construction of reference types
    REF TO type|dobj
    ·        Construction of structured data types
    BEGIN OF struc_type.
    END OF struc_type.
    ·        Construction of table types
    tabkind OF linetype
    These data types only exist during the runtime of the ABAP program.
    Referring to Known Data Types or Data Objects
    Using the additions TYPE or LIKE in the TYPESstatement, local data types in a program can be referred to known data types or data objects. This is mainly the case with user-defined elementary data types. If you declare variables using the additions TYPE type or LIKE dobj with statement DATA, the data type of var is already fully defined before the declaration is made.
    The known types or data that are referred to must be visible at the point where the data type or variable is declared.
    A known data type can be any of the following:
    ·        A predefined ABAP type to which you refer using the TYPE addition
    ·        An existing local data type in the program to which you refer using the TYPE addition
    ·        The data type of a local data object in the program to which you refer using the LIKE addition
    ·        A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.
    The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context.  The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.
    ·        In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.
    ·        You can also refer to the data objects of other visible ABAP programs. These might be, for example, the visible attributes of global classes in class pools. If a global class cl_lobal has a public instance attribute or static attribute attr, you can refer to it as follows in any ABAP program:
    DATA dref TYPE REF TO cl_global.
    DATA:  f1 LIKE cl_global=>attr,
           f2 LIKE dref->attr.
    You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static properties of the class.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm
    thanks
    mrutyun^

  • Data objects in the alert modeler.

    Hi,
    in the default alert modeler profile, there are some data objects.
    Can we add more data objects to this profile..
    As in ... i want to display the campaign information of the business partner in the alert..
    also .. i want to display the last interaction record data like ... date.. description of the interaction record ..
    How can i achieve this.
    Regards
    Vandana Gupta

    hi vandana
    i suppose that u cant add new data object to ur alert modeler,because alert modeler is linked to the meta model and these meta models includes the set of data object which u can use while using a default profile but what u can do is assign new function event as data objects are linked with the events ,that way u can easily incubate ur new data object which u want to use with the alert modeler profile and assign that profile to the IC profile,
    for creating new function events u have to do some coding which is very easy ,if u don know u may ask the same in ur time who knows that.
    guess it will help
    best regards
    ashish

  • Java.util.Calendar returning wrong Date object

    Example: This was my scenario last night. A server in California has date/time of 'Mon Aug 18'. Current time in Indiana is 'Sun Aug 17'. I use Calendar.getInstance(TimeZone.getTimeZone("America/Indiana/Indianapolis")) to return a Calendar instance. I then call the getTime() method on that instance. It should return a Date object relating to that particular time zone. It will not. It defaults back to the server time. When I print out the Calendar instance everything is good, correct date, correct time,etc. WHY WON'T THE getTime() return the correct java.util.Date???
    Following is the output was run today so the dates happened to be the same so focus on the Time. Output includes Server time, new Calendar values, and the Date returned by calendar instance getTime(). See that the Calendar is getting the correct Time.
    SERVER DATE=Mon Aug 18 15:52:13 CEST 2003
    CALENDAR INSTANCE=java.util.GregorianCalendar[time=1061214732975,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Indiana/Indianapolis",offset=-18000000,dstSavings=0,useDaylight=false,transitions=35,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=1,ERA=1,YEAR=2003,MONTH=7,WEEK_OF_YEAR=34,WEEK_OF_MONTH=4,DAY_OF_MONTH=18,DAY_OF_YEAR=230,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=52,SECOND=12,MILLISECOND=975,ZONE_OFFSET=-18000000,DST_OFFSET=0]
    Date from getTime()=Mon Aug 18 15:52:12 CEST 2003

    I got it worked with using DateFormat.parse !
    The trick is to instantiate a new Date object as a result
    of parsing out of 'localized' date string.
    with below code :
    Calendar localCal = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
    localCal.set(Calendar.DATE, 25);
    localCal.set(Calendar.MONTH, 7);
    localCal.set(Calendar.YEAR, 2003);
    localCal.set(Calendar.HOUR_OF_DAY,6);
    localCal.set(Calendar.MINUTE, 38);
    localCal.set(Calendar.SECOND, 11);
    Calendar sinCal = new GregorianCalendar(TimeZone.getTimeZone("Asia/Singapore"));
    sinCal.setTimeInMillis(localCal.getTimeInMillis());
    int date = sinCal.get(Calendar.DATE);
    int month = sinCal.get(Calendar.MONTH);
    int year = sinCal.get(Calendar.YEAR);
    int hour = sinCal.get(Calendar.HOUR_OF_DAY);
    int min = sinCal.get(Calendar.MINUTE);
    int sec = sinCal.get(Calendar.SECOND);
    String sinTimeString = date + "/" + month + "/" + year + " " + hour + ":" + min + ":" + sec;
    System.out.println("VIDSUtil.hostToLocalTime : time string now in SIN time : " + sinTimeString);
    java.util.Date sinTime = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(sinTimeString);
    System.out.println("time in SIN using Date.toString(): " + sinTime.toString());
    It prints out :
    VIDSUtil.hostToLocalTime : time string now in SIN time : 25/7/2003 21:38:11
    time in SIN using Date.toString(): Fri Jul 25 21:38:11 PDT 2003
    (Ignore the PDT, because Date.toString() defaults where the JVM is running)

  • Help on moving frames with new Date()

    I'm a AS beginer and I need help. I trying to move frames accordind to the hour, for example: at 7 am the at frame 1 and at 8 am at frame 10. I have a code that moves the frames every one hour but I need also to move the by the half hour. For instance: at 7 am frame 1, at 7:30 am frame 5, and at 8 am frame 10. This is the code I have so far that moves ever hour:
    // new Date object
    myDate = new Date();
    myHour = myDate.getHours();
    _root.onLoad = function() {
    switch (myHour) {
    //this start at 7 am and end at 6 am
    case 7 :
      trace("It's 7:00 AM");
      switcher_mc.gotoAndStop(1);
      break;
    case 8 :
      trace("It's 8:00 AM");
      switcher_mc.gotoAndStop(3);
      break;
    case 9 :
      trace("It's 9:00 AM");
      switcher_mc.gotoAndStop(5);
      break;
    case 10 :
      trace("It's 10:00 AM");
      switcher_mc.gotoAndStop(7);
      break;
    and so on till 6 am. As you see I need some half hours for some frames.
    I will appreciate any help.
    Thanks in advance
    Pao Pao

    I'm sorry I don't get what you mean. As you see the frame noves when it get to the "case #" like "case 7" it goes to play when is seven am and case 19 goes to play when is 7 pm. what I want is how to get to 7.5 to go and play at 7:30.

  • Calendar and Date objects

    I've got an application that has many Date objects. We frequently have to do comparisons to see if two Date objects represent the same day. I know that I can use a SiimpleDateFormatter to make a String from a Date. I can compare two of these Strings and determine if they are on the same day.
    I also know that I can make two new Date objects from the milliseconds in a pair of Date objects, and set the hour, minute, seconds and milliseconds to zeros. Then, the compareTo method to see if the two days match. But, both of these seem like a huge overhead when I have to do it a lot. (Although the objects are called Date, the compareTo matches the milliseconds version, and so two Date objects from the same day do not match unless they match to the millisecond. Not what I want.)
    Have I overlooked something that returns a nice int or long "Julian day number" field that is quick?
    If I can assure myself that all of the dates were built with a common TimeZone, could I divide by the milliseconds in a day to get a nice day number?

    Maybe an example would clear things up.
    This is a large scheduling application, with a very complex GUI.
    We find out from a database that an activity runs from December 28, 2008 at 10:31AM to January 2, 2009 at 11:45AM.
    The first question after we have converted each date/time pair to a Date object is: "On how many days does this activity take place?" In this case it is 6 days Dec 28, Dec 29, Dec 30, Dec 31, Jan 1, and Jan2. This will be displayed in a JTable with 6 columns. The ideal (at least to me) solution would be to get a day number as described above for the start and end, and know that (end_day - start_day + 1) columns are required, and we can write a for loop to go from the start day to the end day. If we use a semi-day value of the (year*1000 +DAY_OF_YEAR) we have a unique number, but it is useless for determining how many columns are needed in a table. The comparison between 2008363 and 2009002 does not produce a usable result.
    But, there are related operations as part of a more significant activity. We usually have to decide how many days (columns) does it take to display a group of activities. At this level, we don't care what time of days are involved.
    This application is on the desktop of multiple schedulers who will move activities around all day long. We need to be as efficient as possible, since some of the other things are very compute intensive.
    In parts of the application we are very much concerned about time of day, (for example, the custom table cell renderer paints a stripe across the cell of each table cell with a length proportional to the time of day start and end) but in other parts, the day is the main concern.
    I was bothered by the number of Date to Calendar to String conversions being done, and knowing that Date-to-Calendar is not simple due to time zone issues. I also know that Calendar-to-String conversions are not simple since the SimpleDateFormatter has to dynamically interpret a formatting string.
    It looks like I'm just stuck with the way it is, unless the alternative date/time implementation is used. That looks a bit promising.

  • Create custom data object in BAM for a BPM project

    I'm working with 11g (11.1.1.3)
    I have created (via JDEV) a simple BPM process and I have inserted 3 business measurement
    I have set ( as indicated in oracle documentation and in "Getting started") in BPM project :
    project preference --> data target :
    - enable BAM cheked
    - BAM adapter JNDI name : eis/bam/soap
    - in BATCH no cheked
    - data object path : /Samples/Monitor Express
    I have defined new data object in BAM --> Architect
    I have renamed the default data object template in BI_DEFAULT_MyProject_MyProcess (is BI_DEFAULT_businessIndicator_businessIndicator)
    I have added in layout my measurement; I have inserted in the bottom METRIC_myBI1, METRIC_myBI2, METRIC_myBI3 ( are METRIC_Segnalazione METRIC_nSegnalazioni METRIC_misura) of the same type indicated in BPM process
    I have create few istance of the process, but :
    - in the BI_DEFAULT_MyProject_MyProcess content there isn't anything
    - in the default data objects ( COUNTER, INTERVAL, COMPONENT) I find the data of my process
    please help me!!
    I do not know what else to do
    Elena

    CLIENT
    GUID
    PARTNER     
    SALES_ORG
    CHANNEL
    DIVISION     
    POSTING_DATE     
    QUESTION
    ANSWER     
    ANSWER_ID
    SURVEY_ID
    Rating
    CREATED_AT
    CREATED_BY              CHANGED_AT
    CHANGED_BY
    Complete data source name as above.

  • I made a new Apple ID and I want to delete my iCloud account on my iPhone, will it delete only documents or data or it will reset my whole iPhone?

    I made a new Apple ID and I want to delete my iCloud account on my iPhone, will it delete only documents or data or it will reset my whole iPhone, like deleting my apps, contacts. Please I need your help.

    All you have to do is this: Sync your 3GS to create a current backup. Then either: Settings>General>Reset>Erase All Content & Settings or restore it as a "New" device in iTunes. Both accomplish the same thing, erasing all of your data & settings from the phone. You can now give it to your sister, she can plug it into her computer, name it what she wants & sync her content to it. You then restore your 4S from the backup of the 3GS you created when you started. Follow this by syncing your content to your new phone & your 4S will look just like your 3GS.

  • Is there any object in labview that contains a list of data for the user to select (selection one at a time) or add a new data?

    Is there any object in labview that contains a list of data for the user to select (selection one at a time) or add a new data?

    List and table controls -> listbox..is that what you are thinking of?
    The listbox presents the user with a list of options, and you can set it to only accept one selection at a time...Adding new data to the list can not be done directly by the user but if you make e.g. a text control and a button you can programatically insert new objects described in the text box when the button is pressed...(see example).
    If you need more than one column you have the multicolumn listbox. If you want the users to write new entries directly yu can use a table and read selected cells using it's selection start property to read what cell has been selected.
    MTO
    Attachments:
    Listbox_example.vi ‏34 KB

  • How to convert date object format to new?

    Hi,
    I have data object and I want to convert it to this format.
    DD MMM YYYY
    eg: 23 MAR 2003
    I am looking for exact line of code please.
    Thanks,
    Kavans.

    You should check out the Javadoc for java.text.DateFormat and java.text.SimpleDateFormat.
    As for the exact line of code then this would be close:
    Date date = ...; // wherever your date comes from
    DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
    String dateAsString = dateFormat.format(date);Remember to check out those Javadocs, though, 'cos they'll tell you the various formatting options available.
    Hope this helps.

  • I bought a new Iphone 4s, gave the older to my wife , made a new account for her, erased all data and now when i sync them they interfere with the other. Eg: if i delete an app ou buy one it appears on her phone, what shoul I do?

    I bought a new Iphone 4s, gave the older to my wife , made a new account for her, erased all data and now when i sync them they interfere with the other. Eg: if i delete an app ou buy one it appears on her phone, what should I do?

    Have a look here...
    Automatic Downloads...
    http://support.apple.com/kb/ht4539
    Turn off Automatic Downloads. Settings > Store

  • Backup Assistant says "No New Data" even when new entries made in my Droid X

    I have my Droid X set up for a nightly backup.  Every night it runs & then says "No New Data".  I have intentionally added new contacts to my phone contact list to see if it is backed up & it is not.  Does anyone have any idea what I am missing here?  How is this a backup if it doesn't find & store the new information?

    1. Log into Verizon Backup Assistant
    2. Click on Export to CSV
    3. Save File as (or Rename to) Contacts (it should already be converted to CSV so including .csv is redundant)
    4. Log into Gmail/Google Voice
    5. Click on Contacts
    6. Click on Import
    7. Browse for the Contacts (.csv) file
    8. Click Import
    9. Disable BA by going to Settings / Applications . Manage Applications / All Tab / Sync Service / Clear All
    All contacts on your device should sync to Google if they are not in the BA backup...   Now I do say should because no software is perfect.

Maybe you are looking for