How can I calculate the date of a publication? in a common format

0

The java language The ideas is simple I have an now_date and I have pub_date I want to calculate the time between it and put the information in the following way:

if it's a few minutes "6 min ago"

if it's a few hours "6 hours ago"

if it's more than 24 hours "yesterday"

if it is more than 48 hours "on sun 25"

if it is more of the days of the week "last week"

if it's more than a year "2017 jun"

If there is a library or method to make it simpler, they would help me a lot by the time I compare them manually from year to year, month to month, day to day, etc.etc. But it is not reliable in this way since with biceset years it fails me.

    
asked by Diego 28.06.2018 в 01:53
source

1 answer

-1

Java has a method that can help you

System.currentTimeMillis()

The same one that returns the current time in milliseconds.

You can use it in the following way:

long tiempoInicial= tiempoDePublicacion;
long tiempoTranscurrido= System.currentTimeMillis() - tiempoInicial;

There are even more precise methods. Here is the official documentation: link

    
answered by 28.06.2018 / 05:48
source