Home J2me J2ME Convert Date To String



J2ME Convert Date To String
Posted on: November 20, 2008 at 12:00 AM
As in the previous example, you have learned about how to print the current date on the screen. But in this example we are going to convert the date into string.

J2ME Convert Date To String

     

As in the previous example, you have learned about how to print the current date on the screen. But in this example we are going to convert the date into string. 

java.util.Hashtable package contains a method called tostring, that is used to convert the date into string. 

Syntax

public String toString()

 

 

Output of the Convert Date To String MIDlet will be as follow..

Output of the command prompt

Source Code of DateToString.java 

import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class DateToString extends MIDlet implements CommandListener{
  private Display display;
  private Date date;
  private DateField currentDate;
  private Command exit;
  private Form form;
  private int index;
  String dateinstring;
  
  public DateToString(){
  form = new Form("Data and Time");
  date = new Date();
  exit = new Command("Exit", Command.EXIT, 0);
  currentDate = new DateField("", DateField.DATE_TIME);
  currentDate.setDate(date);
  dateinstring = date.toString();
  System.out.println("Date And Time Is In String Format: "+dateinstring);
  }
  
  public void startApp(){
  form.append("CURRENT TIME IS: ");
  index = form.append(currentDate);
  form.addCommand(exit);
  form.setCommandListener(this);
  display = Display.getDisplay(this);
  display.setCurrent(form);
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){
  notifyDestroyed();
  }

  public void commandAction(Command cmd, Displayable s){
  if (cmd == exit){
  destroyApp(true);
  }
  }
}

Download Source Code

Related Tags for J2ME Convert Date To String:
cstringdateconvertioprintscreenviintthisexampletolearnexamearecurrentinasmntouttrhowintoxaxampseeatishamplpregoeaarstrrtscrssriringrenthavstabpleplprono


More Tutorials from this section

Ask Questions?    Discuss: J2ME Convert Date To String  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.