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

  • SEARCH
  • Home
  • 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 8804913
In Process

The Archive Base Latest Questions

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

I am having a string that returns both date and time from database as

  • 0

I am having a string that returns both date and time from database as 2012-11-09 13:20:17. Now I need to take the time from the database string and show the time like 13:20:17 pm if the phone time settings is 24 hour and if the phone time settings is 12 hour I should show it as 01:20:17 pm. The time format can be obtained by this line of code which shows whether its 24hr or 12hr

String timefrmt = Settings.System.getString(context.getContentResolver(),Settings.System.TIME_12_24);
SimpleDateFormat timesettingsFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
date="2012-11-09 13:20:17";
Date myDate=null;
try {
     myDate=timesettingsFormat.parse(date);
} catch (ParseException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
} 
if(timefrmt==null){
     timefrmt="hh:mm aa";
}
SimpleDateFormat timeFormat=new SimpleDateFormat(timefrmt);
String time=timeFormat.format(myDate);

The sample code which I have tried is above but its crashing. Can anyone help me find a way for this.
Thanks a lot

  • 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-14T01:43:52+00:00Added an answer on June 14, 2026 at 1:43 am

    try this

    public static String dateFormateNote(String date) 
    {   
    
        try {
              DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
              DateFormat df2 = new SimpleDateFormat("hh:mm:ss");
              return df2.format(df1.parse(date));
            }
            catch (ParseException e) {
              return date;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting JSON response from the server..Inside that JSON string i am having
I am having problems with working with a third party XML string that contains
I'm trying to sanitize a string that involves user input without having to resort
I'm having some legacy code that recieves a string[,] as one of the method
I'm having trouble finding a regular expression that matches the following String. Korben;http://feeds.feedburner.com/KorbensBlog-UpgradeYourMind?format=xml;1 One
I am having string like String str=<?xml version=1.0 encoding=UTF-8?><head><heading>Appliance Repairs</heading></head><?xml version=1.0 encoding=UTF-8?>Appliance Repairs<?xml version=1.0
I have a string that I load throughout my application, and it changes from
I'm having trouble building a connection string that my VB6 program can use to
I'm having some trouble with Visual Studio 2008. Very simple program: printing strings that
I´m having some trouble retrieving a collection of strings in a projection: say that

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.