Timestamp from Mysql Database into readable

时间:2016-05-17 11:05:16

标签: java android datetime

Hi to everyone please Help me with this problem I am new to android programming. I am developing an android application that the person can post something and as it is needed the post should have a time that shows when it is posted and I have set a column for the time inside mysql database with TIMESTAMP data type and when the post is inserted in the database it also inserts the full time and date that when it is posted but when I get the data from the server it shows the date and time fully like this : 17/5/2016 20:54:34 But I want to show it like readable format like this for Example : 4 hours ago or 3 days ago or 3 months ago Please don't mark my Question as duplicate because I searched and I didn't find anything

1 个答案:

答案 0 :(得分:0)

You should use getRelativeDateTimeString found in the DateUtils class. It will show changes in minutes (0 minutes ago, 2 minutes ago, 3 hours ago, 1 day ago, etc) until the difference reaches a week, then it will just post the full date.

DateUtils. getRelativeDateTimeString(context,dateFromServerLong, DateTimeUtils.MINUTE_IN_MILLIS,DateTimeUtils.WEEK_IN_MILLIS,0);