最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - date-fns subDays - How to get 00:00 time insted of 12:17:35 - Stack Overflow

programmeradmin2浏览0评论

I am trying to change moment for date-fns

    moment: moment().startOf('day').subtract(1, 'day').toDate(),
    date-fns: subDays(new Date(), 1),

Moment give me back this: Moment: Thu Jun 10 2021 00:00:00 GMT+0200 (hora de verano de Europa central)

and date-fns this: Datefn: Thu Jun 10 2021 12:17:35 GMT+0200 (hora de verano de Europa central)

I am wondering if is it any way to get the same time on date-fns. This 00:00:00 instead of this 12:17:35

I am trying to change moment for date-fns

    moment: moment().startOf('day').subtract(1, 'day').toDate(),
    date-fns: subDays(new Date(), 1),

Moment give me back this: Moment: Thu Jun 10 2021 00:00:00 GMT+0200 (hora de verano de Europa central)

and date-fns this: Datefn: Thu Jun 10 2021 12:17:35 GMT+0200 (hora de verano de Europa central)

I am wondering if is it any way to get the same time on date-fns. This 00:00:00 instead of this 12:17:35

Share Improve this question asked Jun 11, 2021 at 10:36 SargentogatoSargentogato 1652 gold badges2 silver badges10 bronze badges 2
  • 2 Have you tried using startOfToday() instead of new Date()? – Jon Skeet Commented Jun 11, 2021 at 10:41
  • No, I haven't but I will, thanks – Sargentogato Commented Jun 11, 2021 at 11:56
Add a ment  | 

1 Answer 1

Reset to default 5

Try this it should work.

date-fns: startOfDay(subDays(new Date(), 1))
发布评论

评论列表(0)

  1. 暂无评论