如何将时间戳转换为用户友好的时间字符串
我希望能够在我的申请中显示“今天”和“昨天”作为最近的日期。我目前正在使用一个日期格式化程序来显示日期(从数据记录中检索),并且将继续使用它超过几天的时间。我真的很喜欢 iPhone 中的短信应用程序显示最近消息日期的方式,并且想模仿这一点。
我必须使用的时间戳是在手机下载数据记录的服务器上生成的。因此,所有时间均按 UTC(即 GMT)时间生成。
我已经为此摆弄了一段时间,我设计的解决方案似乎非常冗长。
谁能建议如何实现可以做到这一点的方法?
干杯 - 史蒂夫。
I want to be able to present "today" and "yesterday" for recent dates in my application. I've got a date formatter in use currently to show dates (retrieved from data records) and will keep using this for anything more than a couple of days old. I just really like the way the SMS app in the iPhone shows dates for recent messages and would like to emulate this.
The time-stamps that I have to work with are generated on a server that the phone downloads the data records from. All times are therefore generated at UTC (i.e. GMT) time.
I've been fiddling about with this for a while the solutions I've devised just seem horribly long-winded.
Can anyone suggest how to implement a method that could do this?
Cheers - Steve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这是一个网络应用程序,您可能会发现 PrettyDate 很有用。我制作了一个 vb.net 实现,可以轻松转换为另一种语言:
If this is a web app, you might find PrettyDate useful. I made a vb.net implementation that could easily be converted to another language: