Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export function parseTime(time, cFormat) {
if (typeof time === 'object') {
date = time
} else {
if (('' + time).length === 10) time = parseInt(time) * 1000
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
if (time.toString().length === 10) time = time * 1000
}
date = new Date(time)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date = new Date(+time)

就可以了吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date = new Date(+time) 会有bug,比如传入的是"01/23/2019"或"2019-01-23"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但还有一个问题 if (time.toString().length === 10) time = time * 1000
if 放的位置不太对吧,这样会导致 十位的number类型时间戳不能正确转化了。

parseTime(1548221490)
//"1970-01-19 06:03:41"
parseTime("1548221490")
//"2019-01-23 13:31:30"

}
const formatObj = {
Expand Down