Search code examples
date-fns

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.


Solution

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