Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js get random data between two dates

function randomDate(start, end, startHour, endHour) {
  var date = new Date(+start + Math.random() * (end - start));
  var hour = startHour + Math.random() * (endHour - startHour) | 0;
  date.setHours(hour);
  return date;
}

console.log(randomDate(new Date(2020, 0, 1), new Date(), 0, 24));
Comment

PREVIOUS NEXT
Code Example
Javascript :: find unique elements in array javascript 
Javascript :: javascript check if number is even or odd 
Javascript :: document load javascript 
Javascript :: react router 404 redirect 
Javascript :: Component should be written as a pure function 
Javascript :: js set cookie 
Javascript :: style display block js 
Javascript :: jetbrains mono 
Javascript :: how to make background image move mmousemove jquery 
Javascript :: stuck at "resolving packages" 
Javascript :: check if intersectionobserver supported js 
Javascript :: jquery add disabled to id 
Javascript :: find vowel & consonants in a string java script 
Javascript :: string contains in react 
Javascript :: random alphabet javascript 
Javascript :: jQuery delete all spans in a div 
Javascript :: javascript sleep 
Javascript :: colors.xml" already exists! 
Javascript :: jquery datepicker set year range 
Javascript :: how to execute javascript cde on window rotate 
Javascript :: js push param to url 
Javascript :: how to make graphql request in axios 
Javascript :: function sytax js 
Javascript :: react absolute import 
Javascript :: javascript remove dom element 
Javascript :: sort an array by characters length in js 
Javascript :: start peerjs server 
Javascript :: fakepath js 
Javascript :: jquery find type submit 
Javascript :: random word generator from alphabets javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =