Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:57:43+00:00 2026-06-14T17:57:43+00:00

Using J2ME, netbeans 7.2, Developing a mobile app.. I have converted the Datefield value

  • 0

Using J2ME, netbeans 7.2, Developing a mobile app..

I have converted the Datefield value to a String and Now want to put it back to a Datefield. To do this I need to convert the String back to Datefield, I am using the following code but its not happening.

long myFileTime = dateField.getDate().getTime(); // getting current/set date from the datefield into long
         String date = String.valueOf(myFileTime); // converting it to a String to put it back into a different datefield

         Date updatedate= stringToDate(date); // passing the string 'date' to the Method stringToDate() to convert it back to date.
                 dateField1.setDate(updatedate); // updating the date into the new datefield1

public Date stringToDate(String s) 
{
    Calendar c = Calendar.getInstance();

    c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(0, 2)));
    c.set(Calendar.MONTH, Integer.parseInt(s.substring(3, 5)) - 1);
    c.set(Calendar.YEAR, Integer.parseInt(s.substring(6, 10)));

    return c.getTime();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:57:45+00:00Added an answer on June 14, 2026 at 5:57 pm

    Since you have mentioned that you have the long myFileTime around, you should be able to use:

    Date updatedate=new Date(myFileTime);
    

    To convert back to your date. If only your String is available, you should modify your function to this:

    public Date stringToDate(String s){
      Calendar c = Calendar.getInstance();
    
      c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(0, 2)));
      c.set(Calendar.MONTH, Integer.parseInt(s.substring(2, 4))-1 );
      c.set(Calendar.YEAR, Integer.parseInt(s.substring(4, 8)));
    
      return c.getTime();
    }
    

    Note the changed indexes.

    In Java SE, you should be able to use the following line, instead of setting each fields separately:

    c.setTimeInMillis(Long.parseLong(s));
    

    Since in s you have the dateField.getDate().getTime() that is equal to myFileTime, the number of seconds starting with January 1, 1970, based on your provided code.

    Your stringToDate should work only if your string will have the following format: ddMMyyyy. Also note that in this case you should use a SimpleDateFormat to parse, something like:

    Date updatedate = new java.text.SimpleDateFormat("ddMMyyyy HH:mm:ss").parse(date);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a mobile app using j2me and lwuit. There is a lcdui DateField
I am using Netbeans IDE (J2ME) for developing a mobile application, a dictionary which
I am developing a mobile app using j2me. It works fine in sony ericsson
Now, we plan for developing a mobile application using j2me. For UI, we go
I'm using NetBeans for J2ME development. Now I want to switch to develop for
I'm developing a BlackBerry app and using J2ME Polish to do the styling. So,
I am developing application using J2ME and LWUIT.I want to run this application on
I'm developing a j2me application using Netbeans IDE and LWUIT library. I need to
I'm developing a j2me application using Netbeans IDE and LWUIT library. I'm using Persian
I am using j2me midp2.0 in Sun Java wireless toolkit 2.5.2. Now I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.