Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home J2me J2ME Convert Date To String

Related Tutorials


 
 

Share on Google+Share on Google+

J2ME Convert Date To String

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 20, 2008

Related Tutorials

Discuss: J2ME Convert Date To String  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com