Convert a Unix timestamp to time in JavaScript

前端 未结 29 2154
渐次进展
渐次进展 2020-11-21 04:57

I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it?

For example, in HH/MM/

29条回答
  •  悲&欢浪女
    2020-11-21 05:34

    The problem with the aforementioned solutions is, that if hour, minute or second, has only one digit (i.e. 0-9), the time would be wrong, e.g. it could be 2:3:9, but it should rather be 02:03:09.

    According to this page it seems to be a better solution to use Date's "toLocaleTimeString" method.

提交回复
热议问题