Date and Calendar object

Hi there,
I am trying to display the current seconds by using the following method. It keeps displaying the first value, over and over. I also tried using the date object and got the same result. Can you help me? Do you know why it does that? Thank you.
Berk Can Celebisoy
Calendar calendar;
calendar = calendar.getInstance();
public static void main(String[] args)
//just to get in the loop
while (2+2==4)
try
System.out.println(calendar.get(calendar.SECOND));
//below line is by using the date object
//System.out.println(date.getSeconds());
this.sleep(1000);
catch (InterruptedException e){}
/////////////////////////////////////

Thanks for your reply.
Berk.
public static void main(String[] args)
Calendar calendar = null;
//just to get in the loop
while (true)
calendar = Calendar.getInstance(); //get the instance
each time u loop
try
System.out.println(calendar.get(calendar.SECOND));
Thread.sleep(1000);
catch (InterruptedException e){}

Similar Messages

  • TableCellEditor that Supports Both Date and Calendar

    Hi,
    I'm trying to write a TableCellEditor that supports both the Date and Calendar Classes (i.e., my table could have either Dates or Calendar objects, and I want this cell editor to work seamlessly with either one).
    Here is a simplified version of my code:
    public class DateCellEditor extends AbstractCellEditor implements TableCellEditor {
    /** The editor component. */
    private DateChooser editor;
    private Calendar cal;
    public DateCellEditor() {
    super();
    editor = new DateChooser();
    cal = Calendar.getInstance();
    public Object getCellEditorValue() {
    cal.setTime(editor.getDateValue());
    return cal;
    public Component getTableCellEditorComponent (JTable table,
                                                                                                                            Object value,
                                                                                                                            boolean isSelected,
                                                                                                                            int row,
                                                                                                                            int column) {
    if (value != null) {
    if (value instanceof Calendar)
         editor.setDateValue(((Calendar)value).getTime());
         else if (value instanceof Date)
         editor.setDateValue((Date)value);
    return editor;
    As you can see, I've already modified getTableCellEditorComponent to accepted object of class Date or Calendar. My problem arises in the getCellEditorValue method. How do I know which type of object to return? In the code sample above, I'm returning a Calendar object, but I'm not sure how to code this method to return either Calendar OR Date.
    By the way, editor.getDateValue() returns a Date object.
    I could easily write two separate TableCellEditors, but I would prefer a more elegant solution. Any ideas?
    Thanks!
    Karen Prengaman

    If you really must have both objects and don't want to convert one into another, you could add a function like
    setMode(int modetype) {}
    where modetype is either DATE or CALENDAR, and then return the set type when the user calls getValueAt

  • Is the only way to import large amount of data and database objects into a primary database is to shutdown the standby, turn off archive log mode, do the import, then rebuild the standby?

    I have a primary database that need to import large amount of data and database objects. 1.) Do I shutdown the standby? 2.) Turn off archive log mode? 3.) Perform the import? 4.) Rebuild the standby? or is there a better way or best practice?

    Instead of rebuilding the (whole) standby, you take an incremental (from SCN) backup from the Primary and restore it on the Standby.  That way, if, for example
    a. Only two out of 12 tablespaces are affected by the import, the incremental backup would effectively be only the blocks changed in those two tablespaces (and some other changes in system and undo) {provided that there are no other changes in the other ten tablespaces}
    b. if the size of the import is only 15% of the database, the incremental backup to restore to the standby is small
    Hemant K Chitale

  • Overview of Dates and Calendar

    hi,
    does anyone know some good links that explain what is going on with Date and Calendar etc..
    It seems quite complicated - is there any docs on the general idea/framework? (and why things have been deprecated etc..)
    I don't know anything about different world calendars, but theres lot on the web, so its more the java specifics I'm interested in!
    thanks,
    asjf

    Don't use Date at all, use Calendar instead (unless you need to use dates in databases). What parts of the Calendar docs aren't clear? The general idea is each instance of Calendar represents a point in time, with methods to change and retrieve various datetime fields.

  • Printing Date with Calendar Object

    I am trying to print the current date of a calender object in a mm/dd/yyyy format.
    When I call system.out.println(now.getInstance()); and scroll through the console, it shows DAY_OF_MONTH=29, YEAR=2006, MONTH=6 for July 29, 2006. I realize months are zero based, so month is really 7. My question is, why does:
    System.out.println(now.MONTH + " " + now.DAY_OF_MONTH + " " + now.YEAR);
    print 2 5 1.
    Logic tells me it should print 6 29 2006.
    I have searched previous posts, and couldn't find one that answers my question. How do I take a Calendar object and print its current set date?

    My question is, why does:My question is: why do you care how a Calendar stores its data? If you want to print it, get a Date instance from it and run it through a SimpleDateFormat to get a String representation of the date.
    Don't mix up data and presentation.
    And to answer your question: you don't print the Calendar's date attributes, but the values of some static constants.

  • Date and Calendar

    Why is it so confusing to get the time
    can someone tell me what's the best way to get the time

    Why is it so confusing to get the time
    can someone tell me what's the best way to get the
    timefrom java.util.Calendar.getInstance you can get a Calendar object which contains current date and time.
    you can use java.text.SimpleDateFormat to get the string which formatted the date or time.

  • Any Expert on Date and Calendar????

    Once I set my own calendar .. why it's not keeping my calendar and printing the date and time onwards from my set date time...
    I just print only one time the date/time but later in my thread, it prints OS date and time....?
    Any Ideas??
    import java.util.*;
    import java.text.*;
    public class DateCheck {
      DateCheck(){
        public static void main(String[] args){
            System.out.println("System  bb");
      //      DateCheck d = new DateCheck();
                   System.out.println("In constructor");
            Calendar d3 = Calendar.getInstance();
            d3.set(Calendar.YEAR,2005);
            d3.set(Calendar.MONTH,Calendar.OCTOBER);
            d3.set(Calendar.DAY_OF_MONTH,27);
            d3.set(Calendar.HOUR,01);
            d3.set(Calendar.MINUTE,01);
            d3.set(Calendar.SECOND,01);
        //    Date dt = new Date(2005,05,01,01,01);
           System.out.println("Start...")  ;
                try{
                    //System.out.println("Here:  " + dfNormal.format(now));
                   // System.out.println("There: " + dfGMT.format(new Date()));
                    System.out.println(" Five seconds Before : " + d3.getInstance().getTime());
          //          System.out.println(" Five seconds Before date : " + dt.getTime());
                    Thread.sleep(5000);
                    //  System.exit(0);
                }catch (Exception e){System.out.println("Some Problems" +e);}
            while(true){
                try{
                    //System.out.println("Here:  " + dfNormal.format(now));
                   // System.out.println("There: " + dfGMT.format(new Date()));
                    Thread.sleep(5000);
                    System.out.println("NOW : " + d3.getInstance().getTime());
            //         System.out.println(" Now date : " + dt.getTime());
                    Thread.sleep(1000);
                    //  System.exit(0);
                }catch (Exception e){}
    }

    Chuck, Thanks for you reply..
    But your solution would 'nt work if some one change the system date..
    I need some solid solution....
    If you do not understand what i am say then do this
    Run your solution.. put it in the thread.... and change your time from
    your computer... and seee what happens....
    Thanks again

  • Ical or Calendar (or whatever) doesn't detect dates and calendar names anymore!

    Hi everyone.
    I used to have a weekly email created with automator and ICal, parsing a specific calendar by its name, and creating
    a list of events occurred in the week (monday to sunday) to send. I used an automator ical alarm for this (now called automator CALENDAR alarm???).
    It worked like a charm.
    Enter Mavericks.
    It's doesn't work anymore.
    Couldn't open the file. So I set to edit it and re-create it, but to no avail.
    I've tried to debug it, by going down to basic actions and their output, and I found out that for example:
    - A one action workflow, find calendar events, with date starting this week, doesn't work!
         No output, when I have pretty many events occurring in the week.
         It doesn't work even if I change the condition (today, or 2 days from now etc...)
    - Another single action workflow (still for testing purposes), filter calendar where title contains any calendar name returns nothing, while there are many calendars in the app!
    Can anyone help?
    Did you experience the same problems?

    Any solution on this problem? I'm experiencing the exact same problem on our 2 GHz iMac Core 2 Duo.

  • Where do Date and Calendar get the current date?

    The server's time is correct, but my Java application is one hour fast... Why could that be?

    Maybe because Java has a different notion of "local time zone" than whatever you use to check the time.
    Try checking the local timezone that Java thinks is in effect and compare this with whatever the OS provides.
    A common case seems to be that Java has more up-to-date timezone data than the OS and Java is actually true.
    And: you could easily make a mistake by converting Date/Calendar/... around an mess up the timezone information (don't ask me how exactly, but I've seen it before).

  • How can I get Chinese characters in the date and calendar?

    The other night I was using a friend's Japanese iBook. I noticed that she the day displayed with a Chinese character in the menu bar and in the calendar widget (e.g., Her clock said 月4:27 instead of Monday 4:27), but her interface was in English (no Japanese menus).
    How can I set the day to display with a Chinese character?
    iBook G4 12   Mac OS X (10.4.8)  

    System Preferences/International/Formats/Region/Japan

  • How to present datetime objects as separate date and time objects?

    Hello,
    I store the working times of employees as records containing two datetime fields:
    - begin: datetime
    - end: datetime
    I would like to keep this design, because a working time may cover several days, e. g. beginning at 2015-04-14 22:00 until 2015-04-15 07:00.
    However, in a simplified user interface, I would like to let the user edit his working times using a date field and two time fields:
    - date: date
    - begin: time
    - end: time
    As a first approach, I created a form in a datasheet view, with the following fields:
    - txt_date: the date (unbound)
    - txt_begin: the begin time (unbound)
    - txt_end: the end time (unbound)
    - begin: the real database field 'begin' (datetime, bound, hidden)
    - end: the real database field 'end' (datetime, bound, hidden)
    When the user edits the fields txt_date, txt_begin and txt_end, I catch the AfterUpdate event and then update the database fields begin and end.
    This seemed to work at the first sight. However, then I noticed that changes to the database bound fields affect all rows of the datasheet view. So this is not a suitable solution yet.
    Is there any trick to get this to work? I also have other use cases where I want to modify fields in a datasheet view...
    Thanks
    Magnus

    You need to assign values to the bound controls in each of the unbound controls' AfterUpdate event procedures, as follows:
    Private Sub txt_Date_AfterUpdate()
        Me.Begin = CDate(Nz(Me.txt_Date)) + CDate(Nz(Me.txt_Begin))
        Me.End = CDate(Nz(Me.txt_Date)) + CDate(Nz(Me.txt_End))
    End Sub
    Private Sub txt_Begin_AfterUpdate()
        Me.Begin = CDate(Nz(Me.txt_Date)) + CDate(Nz(Me.txt_Begin))
    End Sub
    Private Sub txt_End_AfterUpdate()
        Me.End = CDate(Nz(Me.txt_Date)) + CDate(Nz(Me.txt_End))
    End Sub
    This assumes that no shift spans midnight of course.  For an example of how to handle shifts spanning midnight take a look at Timesheet.zip in my public databases folder at:
    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.
    This little demo file includes functions which handle values entered as times where a shift might span midnight, assuming that a shift will always be less than 24 hours duration.  
    Ken Sheridan, Stafford, England

  • Question on Dates and Calendar

    i need to find the number of days between 2 given dates. For example, the number of days between Nov 29th 2006and Dec 3rd 2006 is 4. The number of days between Nov 10th and Nov 15th is 5. How do i do this? Is there an api for doing this?

    No API does this; by using the Claendar and related classes it's easily calculated. See these:
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=date+difference&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums

  • Financial Reporting - Derived data and calendar periods

    I have two questions with Financial Reporting
    1. I have a P&L report that shows the full 12 months. FR displays the derived data of the next actual period even if there has been no consol. It therefore looks like all the data has been reversed to zero. Is there a setting to stop FR from displaying derived data?
    2. The application has a June year end. We want to display in the report titles the months based on their calender year rather than the fiscal year. This means that for Sept we want Sept 2011 to display, not Sept 2012 that will come from the Year dimension. Is there a function to handle that?
    regards

    1. I have a P&L report that shows the full 12 months. FR displays the derived data of the next actual period even if there has been no consol. It therefore looks like all the data has been reversed to zero. Is there a setting to stop FR from displaying derived data?
    The answer for this might be the VIEW dimension.If u have taken YTD please change it to Periodic and give a try.
    2. The application has a June year end. We want to display in the report titles the months based on their calender year rather than the fiscal year. This means that for Sept we want Sept 2011 to display, not Sept 2012 that will come from the Year dimension. Is there a function to handle that?
    While creating application profile we have a choice to select the years or just look into application settings.I am not sure just give a try.

  • Date and Calendar Classes

    Well, I'm trying to do a program which valildates a Date given by the User (Does it matter if it's an example using the console, or not?? 'Cuz I'm using it on a Swing application). I WAS using
    date's constructor:
    new Date(y, m, d); but it doesn't do a thing, I can make a new instance
    of Date EVEN if it's February 31st (WHICH IS NOT RIGHT!!!)... how can I do it??

    Im not really sure if I understand what your asking, but I thnk that in the constructor you need some stuff like
    if ( m > 12){
          m = 0
    if ( m == 2 && d > 28 ){ // that would be just for febuary
          d = 0
    }But you probobly would have to do that for every month.
    hope this helps

  • ABAP OO:  Duplication of selected data in created objects?

    I am new to ABAP OO and I have a conceptual question/concern that I cannot resolve.  Can someone explain what I am missing?
    I would think that selecting and storing (in internal tables) a large amount of data from many related database tables and, at the same time, creating and storing objects from this same data would unnecessarily consume a huge amount of memory.  To avoid this problem, it seems that the selected data and created objects should not be stored in internal tables simultaneously.
    Does this concern make sense?  If so, how is this problem best handled?
    Does it make sense to delete the corresponding data once the objects are created (to free memory)?
    Or does it make sense to keep the data and only temporarily create objects as needed?
    Thanks.

    Hello Matt
    The approach you describe is to select data first and the feed the object instances with them. <b>Why not let the object instances do the data selection themselves?</b>
    I will give you an example what I mean.
    (1) Lets assume I want to write an application that allows to deal with cost center hierarchies. On the selection screen you can choose one or many cost center hierarchies.
    (2) Using the selection criteria I would select all cost center hierarchies but without any details (just the key values).
    (3) Next I would loop over the cost center hierarchies and create a cost center hierarchy instance (a class you have to define yourself) for each key value. The CONSTRUCTOR of this class will have an IMPORTING parameter like <i>id_kostl_hier</i>.
    (4) In the CONSTRUCTOR method I first check if the cost center hierarchy exists (if not raise an exception-class based exception) and then do the selection of the hierarchy details (e.g. the cost centers).
    (5) The instances are collected in an itab of the "frame" application.
    Using this approach you will have little duplication of data within your application. Furthermore, if you really have to deal with huge amounts of data then you could read them only on demand (like in tree controls where the sub-nodes usually are read when the parent node is expanded).
    Hope I could give you some fresh insights into this exciting topic.
    Regards
      Uwe

Maybe you are looking for

  • How do I set up the iPhone to become a modem for Wifi to my computer?

    When I take my notebook to areas without Wifi, how do I set up my iPhone to be the modem that will let me get online on my notebook using the iPhone and bluetooth to make the connection. Do I need a modem script to make the connection work? What are

  • Server not recognizing a valid connection

    Hi, After reading about Java NIO for some time I have built a server and very simple client. The server accepts connection requests and stores them as non blocking socket channels in a selector. The selector executes the select() method every second.

  • Adobe Creative Suite 5.5 design standards (Student and teacher licensing) download

    I had purchase Adobe Creative Suite 5.5 design standards (Student and teacher licensing), but I lost the disk and still have my product code. I tried downloading from the available downloads but the product code i have doesn't work. Where can i find

  • Maintaining F4 help in Secondrylist

    Hi,         Can anyone please tell me how to maintain F4 help in Secondary list         using Object Oriented Programming ?         Regards,         Madhu latha.

  • Can't get Solaris 8 to show my second hard drive.

    I installed Sol8 on a 1 hard drive intel machine (as the only OS, no windows). Later, I added a second hard drive, and after running the device config assistant (DCA) still doesn't show it in the list of drives under the 'format' command. Physically,