简体   繁体   中英

Where should date representation should be handled on API or on mobile app?

我们有返回一些日期的API,并且有使用该日期的移动应用程序,但是它以不同的格式(例如10分钟前)表示此日期,那么在API上或从移动应用程序处理日期表示的最佳方法是什么?

If you need to be able to change the representation without redeploying / re-releasing the app you should represent it on the server.

Alternatively you could represent it in UTC on the server and have each client of the API responsible for displaying the information based on their own needs. This places more responsibility on the client, but keeps the server ignorant of display concerns.

you can also get the reference of current time via currentTime - difference then calcualte the actual time to display properly through SimpleDateFormat API, although its better to handle it on server side using UTC time.

you can calculate the current time through Calendar API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM