Jiaah
Jiaah

Reputation: 844

date-fns format(fromUnixTime(1584161862798), 'yyyyMMdd') invalid time value

I am using date-funs library to manage dates. ( version 2.12.0 ) I need to format unix datetime to 'yyyyMMdd'. And I am getting 'invalid time value' error.

fromUnixTime(1584161862798) 
// Sat Feb 03 52170 22:13:34 GMT+0900 (대한민국 표준시)

format(startDate, 'yyyyMMdd');
// invalid time value

I am nor sure why this is not working, when

format(new Date(), 'yyyyMMdd')
// 20200413

this works.

I tried to parse the date. It still returns the same error.

format(parseISO(startDate), 'yyyyMMdd');
// invalid time value

Thanks in advance.

Upvotes: 8

Views: 21160

Answers (2)

Richard Bonneau
Richard Bonneau

Reputation: 1214

Another answer on here is close but here's what worked for me:

format(new Date('yourUnixDateTime' * 1000), 'yyyyMMdd')

Upvotes: 13

Jiaah
Jiaah

Reputation: 844

format(new Date('yourUnixDateTime'), 'yyyyMMdd')

Upvotes: 4

Related Questions