in Education by
There are loads of questions about the current date in JavaScript in general, but in my scenario, I have to pass in something to the date object, because usually there is a valid date I'm looking for. However, my question is - assuming the argument is undefined, what should I pass to mimic new Date()? As an example, my code will do something like this. const date = '2019-11-26T19:10:12.000Z' const diff = new Date(date).getTime() - new Date().getTime() While my components are rendering, I need to give date an initial value (while it loads from the server). During this initial loading time, I expect the diff to equal 0. I have tried the following new Date(undefined) >> Invalid Date new Date('') >> Invalid Date new Date(null) >> Thu Jan 01 1970 new Date(0) >> Thu Jan 01 1970 I'm trying to solve it in a simple way, by passing in whatever value would match no argument for Date. It seems weird, but if it's the case, I'll just assume it's JavaScript date objects being weird. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can define your date with another date object as parameter. var params = new Date; var date = new Date(params); console.log(date) Run code snippetExpand snippet

Related questions

0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I am trying to return an javascript value with Awesome lib in Vb.net / C#. Now I know how to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am using an array in order to calculate large powers of 2. The arrays add to each other and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have a simple WCF service that I'm exposing using a .svc. The service has some related DataContract ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Should I learn JavaScript or Python? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Is there a better way than this to splice an array into another array in javascript var string = ' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I am attempting to solve a problem where if the elements in one array are squared, and all of the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I have function of "endgame" and here's how the function goes function endgame() { setScreen("scorescreen" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    I write a lot of dynamically generated content (developing under PHP) and I use jQuery to add extra ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have a mobile website that plays a background song. When I pressed the home button on my phone ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    How will you get the instant of current date in terms of milliseconds using java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get the current date using local datetime api of java8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    I am trying to redirect to another site then run code on it. function gotonewpage() { window.location. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
...