skip to Main Content

I want to change my below 3 lines to just 1 line.

const date = todayDate(); //console-log: 2023-11-4
const timesasaddastamp = Date.parse(date);
const businessDayDate = new Date(timesasaddastamp); // console-log: Sat Nov 04 2023

How to shorten this?
I tried doing:

const businessDayDate = new Date.parse(date);

2

Answers


  1. If you want today in form of Sat Nov 04 2023, you can simply write this:

    const businessDayDate = new Date();
    

    Else, you can write like this:

    const businessDayDate = new Date(Date.parse(todayDate()));
    
    Login or Signup to reply.
  2. You can achieve the same result in one line by chaining the operations. Here’s how you can do it in one line:

    const businessDayDate = new Date().setHours(0, 0, 0, 0);
    

    This code will create a Date object for the current date and time and set the time to midnight (00:00:00:000) in one line.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search