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 274433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:36:35+00:00 2026-05-12T00:36:35+00:00

How to extract time portion from a Date-object and use it as a String

  • 0
  1. How to extract time portion from a Date-object and use it as a String in J2ME?

  2. How to convert that time-string back to Date – object in J2ME?

I have done something to achieve this, but it is not showing correct-time.

  • 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-05-12T00:36:35+00:00Added an answer on May 12, 2026 at 12:36 am

    I use the following code to get time:

    String getDateString(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
    
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
    
        return new String(/*Any format you need*/);
    }
    

    You get numbers and then you can output them in any necessary format.

    The code to create Date object is something like this:

    Date createDate(String dateString) {
        //Extract needed numbers first
        StringBuffer strBuf = new StringBuffer(dateString);
    
        char[] charBuf = new char[4];
    
        strBuf.getChars(0, 3, charBuf, 0);
        dayOfWeek = new String(charBuf, 0, 3);
    
        strBuf.getChars(strBuf.length() - 4, strBuf.length(), charBuf, 0);
        year = charsToInt(charBuf, 4);
    
        strBuf.getChars(4, 7, charBuf, 0);
        String monthStr = new String(charBuf, 0, 3);
        month = ArraySearcher.searchStringEntry(monthStr, MONTHS);
    
        day = extractShortField(strBuf, 8, charBuf);
        hour = extractShortField(strBuf, 11, charBuf);
        minute = extractShortField(strBuf, 14, charBuf);
        second = extractShortField(strBuf, 17, charBuf);
    
        //Now set the calendar
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, second);
    
        return calendar.getTime();
    }
    
    private int charsToInt(char[] buf, int len) {
        String str = new String(buf, 0, len);
        return Integer.parseInt(str);
    }
    
    private int extractShortField(StringBuffer strBuf, int start, char[] charBuf) {
        strBuf.getChars(start, start + 2, charBuf, 0);
        return charsToInt(charBuf, 2);
    }
    

    That’ll do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 173k
  • Answers 173k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer as_a() allows you to convert the expression to a specific… May 12, 2026 at 2:43 pm
  • Editorial Team
    Editorial Team added an answer Using XML as your database will work fine as long… May 12, 2026 at 2:43 pm
  • Editorial Team
    Editorial Team added an answer Use the Apache StringEscapeUtils.escapeJavaScript function. Escapes the characters in a… May 12, 2026 at 2:43 pm

Related Questions

I'm converting an existing program to C++ and here need to manipulate Sybase timestamps.
How to properly extract a time only from the datetime object ( post.created_at ,
I've got this date time string: post[date] = 2007-07-18 10:03:19 I'd like to extract
I have an ASCII log file with some content I would like to extract.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.