×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Mar 2010
    Posts
    136

    How to show current time?

    I want to display the current time, but not date.
    I wrote as the following but it does not show current time.
    date=new DateField("Date",DateField.TIME);
    today=new Date(System.currentTimeMillis());
    date.setDate(today);
    Last edited by komomo; 2010-07-15 at 04:38.

  2. #2
    Registered User
    Join Date
    Dec 2009
    Location
    Bangalore/Mysore, Karnataka, India.
    Posts
    43

    Re: How to show current time?

    Hi komomo,

    You will have to add the 'DateField' to some displayabe (like Form). When you display that Form, the DateField will be displayed in it.
    it will be something similar to this.
    [CODE]aForm.append(date);
    Display.getDisplay(some_midlet).setCurrent(aForm).[/CODE
    ]
    -Roopesh.
    (http://trivialdust.blogspot.com/)

  3. #3
    Regular Contributor
    Join Date
    Mar 2010
    Posts
    136

    Re: How to show current time?

    I have added to a Form and it was also displayed on the screen.
    But instead of showing current time, it just shows hh:mm??

  4. #4
    Registered User
    Join Date
    Dec 2009
    Location
    Bangalore/Mysore, Karnataka, India.
    Posts
    43

    Re: How to show current time?

    Hi,

    There is no problem in your code. Can u your tell more about ur code?

    BTW, try this code it works on my emulator.
    Code:
    import java.util.Date;
    import javax.microedition.lcdui.DateField;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    
    public class HelloWorld extends MIDlet {
    
    	public HelloWorld() {
    		Form aForm = new Form("Hello World");
    		DateField dateField = new DateField("Date", DateField.DATE);
    		dateField.setDate(new Date());
    		aForm.append(dateField);
    		Display.getDisplay(this).setCurrent(aForm);
    	}
    
    	protected void destroyApp(boolean unconditional)
    			throws MIDletStateChangeException {
    	}
    
    	protected void pauseApp() {
    	}
    
    	protected void startApp() throws MIDletStateChangeException {
    	}
    
    }
    -Roopesh.
    (http://trivialdust.blogspot.com/)

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: How to show current time?

    try
    Code:
    Date today=new Date();
    String date=today.toString();
    // put in some String manipulations to get Time is in HH:MM:SS format.
    toString
    public String toString()Converts this Date object to a String of the form:
    dow mon dd hh:mm:ss zzz yyyy
    where:
    dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
    mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
    dd is the day of the month (01 through 31), as two decimal digits.
    hh is the hour of the day (00 through 23), as two decimal digits.
    mm is the minute within the hour (00 through 59), as two decimal digits.
    ss is the second within the minute (00 through 61, as two decimal digits.
    zzz is the time zone (and may reflect daylight savings time). If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.
    yyyy is the year, as four decimal digits.
    Thanks,
    Ekta

  6. #6
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Re: How to show current time?

    check:
    new DateField("", DateField.DATE_TIME);

    For more reference :
    http://www.java2s.com/Code/Java/J2ME/DateField.htm
    thanks,
    jitu_goldie..

    KEEP TRYING..

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    214

    Re: How to show current time?

    http://discussion.forum.nokia.com/fo...lease-help-me-.........................

    hi roopesh can u please help me in the task that I performing in the link above

  8. #8
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: How to show current time?

    Quote Originally Posted by kumarv75 View Post
    http://discussion.forum.nokia.com/fo...lease-help-me-.........................

    hi roopesh can u please help me in the task that I performing in the link above
    Please use Private Messaging for such messages not this Discussion Board. Click on Roopesh Name on the left side, his profile will open, click on Private message, write what ever you want to and Send.
    Thanks,
    Ekta

  9. #9
    Registered User
    Join Date
    Sep 2009
    Location
    Bangalore, India
    Posts
    49

    Thumbs up Re: How to show current time?

    Quote Originally Posted by ektasrv View Post
    Please use Private Messaging for such messages not this Discussion Board. Click on Roopesh Name on the left side, his profile will open, click on Private message, write what ever you want to and Send.
    Use the following code for the same:

    PHP Code:
    Calendar cal Calendar.getInstance();
    cal.setTime(new Date());
    System.out.println" Current HOUR: " Calendar.HOUR);
    System.out.println" Current MINUTE: " Calendar.MINUTE);
    System.out.println" Current SECOND: " Calendar..SECOND); 
    Regards
    Nilanchala

  10. #10
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: How to show current time?

    Quote Originally Posted by nilanchalapanigrahy View Post
    Use the following code for the same:

    PHP Code:
    Calendar cal Calendar.getInstance();
    cal.setTime(new Date());
    System.out.println" Current HOUR: " Calendar.HOUR);
    System.out.println" Current MINUTE: " Calendar.MINUTE);
    System.out.println" Current SECOND: " Calendar..SECOND); 
    Above will just print the values of Calendar fields HOUR,MINUTE & SECONDS not the real value of these
    it should be
    Code:
    System.out.println( " Current HOUR: " + cal.get(Calendar.HOUR));
    System.out.println( " Current MINUTE: " + cal.get(Calendar.MINUTE));
    System.out.println( " Current SECOND: " + cal.get(Calendar.SECOND));
    System.out.println( " Current AM/PM: " + cal.get(Calendar.AM_PM));
    Thanks,
    Ekta

  11. #11
    Regular Contributor
    Join Date
    Mar 2010
    Posts
    136

    Re: How to show current time?

    Thanks for the replies.
    But what I want to know is how to set the current time using DateField class.
    I want to show only the time such as 11:51 AM , not the complete date such as July 14, 2010,11:51 AM.

    date=new DateField("Date",DateField.TIME);//I chose DateField.Time because I just want to show the current time
    //today=new Date(System.currentTimeMillis());
    today=new Date();
    date.setDate(today);

Similar Threads

  1. CSmsMessage::Time() returns current time instead of the time of sms creation
    By elviin in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2010-04-30, 12:06
  2. Get Date and Time current?!
    By beobeo796 in forum Mobile Java General
    Replies: 0
    Last Post: 2010-04-21, 04:37
  3. Don't show password first time but show second time
    By abdullah.jobayer in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-04-10, 08:56
  4. Replies: 3
    Last Post: 2008-07-21, 09:59
  5. How to get current time?
    By znakharenko in forum Symbian
    Replies: 2
    Last Post: 2005-12-03, 15:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×