关于 java:Timestamp 从 Mysql 数据库变成可读的 | 珊瑚贝

Timestamp from Mysql Database into readable

本问题已经有最佳答案,请猛点这里访问。


大家好,请帮我解决这个问题,我是 android 编程新手。
我正在开发一个 android 应用程序,该人可以发布一些东西,并且根据需要,帖子应该有一个显示发布时间的时间,并且我在 mysql 数据库中使用 TIMESTAMP 数据类型设置了一个时间列,以及发布的时间插入数据库中,它还插入了发布时的完整时间和日期,但是当我从服务器获取数据时,它显示的日期和时间完全如下:17/5/2016 20:54:34
但我想以这样的可读格式显示它,例如:4 小时前或 3 天前或 3 个月前
请不要将我的问题标记为重复,因为我进行了搜索但没有找到任何内容

  • 下次请看起来更好:)


您应该使用 DateUtils 类中的 getRelativeDateTimeString。它会以分钟为单位显示变化(0 分钟前、2 分钟前、3 小时前、1 天前等),直到差异达到一周,然后它才会发布完整日期。

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

来源:https://www.codenong.com/37274317/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9369.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?