Spirit Spirit - 1 year ago 104
Android Question

Convert long Timestamp to shorter Timestamp

I have a Timestamp in this format: 1479912701805

If you check on
http://www.epochconverter.com/ you can see that date is

GMT: Wed, 23 Nov 2016 14:51:41.805 GMT

Now I need to shorten that long to
1479859200 which is 3 number shorter, I guess milisecs

Answer Source

From your data in example, you need to remove hours, minute and seconds from the value first. Using the % will be enough.

Remove the remainder of the number of milliseconds of a day from this value.

    l -= l% (1000*60*60*24);

A small example : Calendar c = Calendar.getInstance();

    long l = 14798592701805l;

    l -= l% (1000*60*60*24);

Then, just divide this by 1000 to remove the 3 first digit

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download