×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    Question Get the date as String from j2me form

    Hi all.

    I am using j2me form for getting the user date. I want to get the date as string. For this I am using

    DateField datefield = new DateField("Enter Date",DateField.DATE);
    Date strDate=datefield.getDate();
    String strLabel=strDate.toString();
    System.out.println("Date "+strDate);
    System.out.println("Date as string"+strLabel);

    Here I have entered the date like 01/04/2006. But this code returned the value java.util.Date@0. If I want to get the date value which I have entered means, what I will do?


    Anyone help me pls...


    Thanks.

  2. #2
    Regular Contributor
    Join Date
    Sep 2006
    Posts
    101

    Re: Get the date as String from j2me form

    date's toString must return its sting rep...wht;s the last line output...???

  3. #3
    Regular Contributor
    Join Date
    Jan 2006
    Posts
    90

    Re: Get the date as String from j2me form

    hi
    try this code....
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH)+1;
    int date = calendar.get(Calendar.DATE);

    now u have year, month and date. U can use it to print in the format u want. I don't think date.getDate().toString() will give u the string representation.
    date.toString() will give u a representation of date in the following format Mon Sep 25 14:44:55 UTC 2006.
    Last edited by jini_1; 2006-09-25 at 15:47.

  4. #4
    Regular Contributor
    Join Date
    Aug 2006
    Location
    Rawalpindi, Pakistan
    Posts
    486

    Re: Get the date as String from j2me form

    date.getdate will not be a string representation. u will have to convert it and the code given above works excellent. ihave just checked it.
    Regards
    Nouman

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1

    Re: Get the date as String from j2me form

    hi
    the above code is give the date format as Mon Sep 25 14:44:55 UTC 2006.,but i want only 25/09/2006.what will do..?Any suggession please..?
    thanks in advance..

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Get the date as String from j2me form

    the solution from jini_1 shoud work:

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH)+1;
    int date = calendar.get(Calendar.DATE);

    String dateString = date + "/" + month + "/" + year;

Similar Threads

  1. Diff b/w Form and Tabbed form in J2me polish
    By divyas in forum Mobile Java General
    Replies: 2
    Last Post: 2007-11-21, 09:53
  2. convert Date object to string
    By artemg in forum Mobile Java General
    Replies: 4
    Last Post: 2006-03-03, 04:56
  3. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52
  4. String to Date
    By Supraja in forum Mobile Java General
    Replies: 1
    Last Post: 2003-07-28, 13:43
  5. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

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