×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    25

    Get Date and Time current?!

    I want show current date and time of my phone in this way:
    Date: ddmmyyyy
    Time: hhmmss


    with no character / or :
    Can you guy help me?! Thanks.
    I'm at GMT +7, here is my code:


    Code:
     package FunctionTest;
    
    import java.util.Calendar;
    import java.util.Date;
    import java.util.TimeZone;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.*;
    
    /**
     * @author Duy Pham
     */
    public class Show extends MIDlet implements CommandListener
    {
        private Form form;
        private Command exit, date, time;
        private Display dis;
        private Calendar cal;
        private long d1, d2;
        private String si1, si2;
    
        public Show()
        {
            form = new Form("Show Data");
            Date d = new Date();
            cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
            cal.setTime(d);
    
            d1 = cal.get(Calendar.DAY_OF_MONTH) + cal.get(Calendar.MONTH) + cal.get(Calendar.YEAR);
            d2 = cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE) + cal.get(Calendar.SECOND);
    
            exit = new Command("Exit", Command.EXIT, 0);
            date = new Command("Date", Command.SCREEN, 1);
            time = new Command("Time", Command.SCREEN, 2);
    
            form.addCommand(exit);
            form.addCommand(date);
            form.addCommand(time);
            form.setCommandListener(this);
    
            dis = Display.getDisplay(this);
            dis.setCurrent(form);
    
        }
    
        public void startApp()
        {
        }
    
        public void pauseApp()
        {
        }
    
        public void destroyApp(boolean unconditional)
        {
        }
    
        public void commandAction(Command cmd, Displayable d)
        {
            if (cmd == exit)
            {
                notifyDestroyed();
            }
            else if (cmd == date)
            {
                si1 = "Date: " + d1;
                form.append(si1);
                Display.getDisplay(this).setCurrent(form);
            }
            else if (cmd == time)
            {
                si2 = "Time: " + d2;
                form.append(si2);
                Display.getDisplay(this).setCurrent(form);
            }
        }
    }
    Last edited by beobeo796; 2010-04-21 at 05:13.

Similar Threads

  1. Getting current date and time
    By Deepa msc in forum Mobile Java General
    Replies: 6
    Last Post: 2008-06-25, 10:08
  2. how to get the current time and date
    By Bhoopathi Kummara in forum Symbian
    Replies: 4
    Last Post: 2008-01-08, 11:32
  3. Pim toSerialFormat writes the current time and date
    By ianstrain in forum Mobile Java General
    Replies: 2
    Last Post: 2007-09-20, 10:09
  4. Displaying Current date time in SMS??
    By arunjadhav_v in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2005-08-13, 12:22
  5. How to display current time and date?
    By yanxiang in forum Symbian
    Replies: 3
    Last Post: 2004-03-10, 15:19

Posting Permissions

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