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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:44:55+00:00 2026-05-24T12:44:55+00:00

I am trying to display in a TextView when my application last updated (e.g.,

  • 0

I am trying to display in a TextView when my application last updated (e.g., “Last updated at 12:13). I am trying to use a Calendar instance and I thought I understood it correctly but I seem to be having trouble. I know to get an instance I use the method Calendar.getInstance(). And then to get the hour and minute I was using Calendar.get(Calendar.HOUR) and Calendar.get(Calendar.MINUTE). My minute field returns correctly but Calendar.HOUR is returning the hour on a 24 hour clock and I want a 12 hour clock. I thought HOUR_OF_DAY was 24 hour clock. Where am I going wrong?

Here is the code I’m using:

Calendar rightNow = Calendar.getInstance();
mTv.setText("Refreshed! Last updated " + 
           rightNow.get(Calendar.HOUR) + ":" + 
           rightNow.get(Calendar.MINUTE) + ".");

mTv is my TextView that I’m updating. Thanks for any help.

Also, it would be ideal if I could say “Last updated 5 minutes ago.” instead of “Last updated at 12:13pm”. But I’m not sure the best way to have this update each minute without draining resources or the battery…?

  • 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-24T12:44:56+00:00Added an answer on May 24, 2026 at 12:44 pm

    I’d recommend using SimpleDateFormat in combination with the Date class for formatting the time:

    Date now = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("K:mm a");
    String formattedTime = sdf.format(now);
    

    Short explanation how it works:
    You create a SimpleDateFormat object and pass a String to it’s construtor which tells it how to format every time/date object that gets passed to the format() function of it.
    There are plenty of constants/letters which represent a special time object (e.g. seconds, an AM/PM marker, .. see the class documentation for the full list).

    "K:mm a" means a "11:42 AM" format – one or two digits for the hour (depending on its value) in a 12 hour format, always two digits for minutes (mm) and either AM or PM (a), depending on the time.

    After you did that, just pass a Date object to the format() function, and you’ll get a formatted string. Note that a Date just holds one single point in time, if you create it from the constructor with no arguments ("= new Date()") it uses the current time. If you need another time, you can pass a long argument with the millis, you may get that from Calendar.getTimeInMillis().

    As of implementing the "updated XY minutes ago function" – yes you’d have to update this every minute and you have to calculate the difference between the update and the current time. I’d say it’s not worth it from a battery and extra work perspective.
    If your app uses standard short update cycles (e.g. every hour or somthing along those lines) and is not fullscreen, the user has a visible clock on top/bottom of his screen. If he really wants to check how long it was since the update, he can take a short look and compare (mostly just minutes or hours/minutes). And IMHO thats no inconvinience for a user, at least it would not for me. I’d just compare without thinking about that. But I tend to kill apps which waste my battery for no useful reason.

    Also note that not everybody uses a 12-hour format. To get a localized time format depending on users settings/country use DateFormat.getTimeInstance(). This returns a DateFormat, but this works like the SimpleDateFormat, just pass a time to format().

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

Sidebar

Related Questions

I'm trying to display the \u25BA unicode character in a textview, but doing <TextView
I've been trying to display text using a Quartz context, but no matter what
I'm trying to display an array of files in order of date (last modified).
i am trying to display STRING my car name is abc in textview. it
I have a android webservice client application. I am trying to use the java
I am trying to display the list of songs using array adapters. But the
For an Android application, I'm trying to use a Spinner which, when an option
I'm trying to display separate items in a list row. So i use 4
I'm trying to do a karaoke-like application . I want to display a word
In my Android application I am trying to display German Text. ö ä ü

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.