Indicate Android registration time

Asked 2 years ago, Updated 2 years ago, 33 views

1. In the case of Facebook, when I post a post, it shows how many hours ago I registered, and I want to implement it like this.

Does this mean that when the stored time is loaded, we have to create a function that compares it to the current time?

Or is there another way?

Currently, the server stores "201606231756" in 11 digits.

2. Are there any examples or keywords that have already been implemented?

I am currently using Android and PHP.

android php

2022-09-22 21:31

1 Answers

Convert the time value stored on the server to milliseconds and use the following API provided by Android DateUtils.

DateUtils.getRelativeTimeSpanString(milliseconds)

The results are printed in the following format: (Results in US format)

3 min. ago, 10:15 AM
Yesterday, 12:20 PM
Dec 12, 4:12 AM
11/14/2007, 8:20 AM

The simplest way is to call a function with one parameter mentioned above, and you can also change the minimum time range (for example, 0 minutes when less than 1 minute) and formatting. Refer to the official document for a detailed description of the parameters.


2022-09-22 21:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.