how to show 1 day ago in javascript

Solutions on MaxInterview for how to show 1 day ago in javascript by the best coders in the world

showing results for - "how to show 1 day ago in javascript"
Kristy
22 Nov 2019
1function timeSince(date) {
2
3  var seconds = Math.floor((new Date() - date) / 1000);
4
5  var interval = seconds / 31536000;
6
7  if (interval > 1) {
8    return Math.floor(interval) + " years";
9  }
10  interval = seconds / 2592000;
11  if (interval > 1) {
12    return Math.floor(interval) + " months";
13  }
14  interval = seconds / 86400;
15  if (interval > 1) {
16    return Math.floor(interval) + " days";
17  }
18  interval = seconds / 3600;
19  if (interval > 1) {
20    return Math.floor(interval) + " hours";
21  }
22  interval = seconds / 60;
23  if (interval > 1) {
24    return Math.floor(interval) + " minutes";
25  }
26  return Math.floor(seconds) + " seconds";
27}
28var aDay = 24*60*60*1000;
29console.log(timeSince(new Date(Date.now()-aDay)));
30console.log(timeSince(new Date(Date.now()-aDay*2)));
queries leading to this page
how to show 10days ago in javascripttime ago calculator js codehow many hours ago javascriptdisplay date time in hours ago javascripttimeago jvscriptjs date 1 day agojavascript convert date to days agojs library 5 minute agoposted 2mins ago in javascriotjavascript date 2b 1 dayjavascript timeagojavascript return date 1 day agotime days ago javascripthow to get the date of one day ago jstime ago in javascripttimeago jsjs 1 day agoconvert js date to days agojavascript to days ago from current datejs timeagojavascript time ago functiondisplay date time in hours ago or after utc javascripthours ago javascripthow to calculate one day against date in javascriptjavascript date from one day agojavascript date one day agojs time agohow to calculate days ago from time javascriptget date one day ago javascripthow to get 30 day ago date to day in javascriptjavascript date 1 year agohow can we get hrs ago text in javascripttime ago jsjavascript to check time agodisplay time as time ago javascriptjs get date ten days agojs time sincejs date is minute agojavascript to check day agojavascript date 2b1 daytypescript ago timeshow date as days ago in jstimeago in jsparse time ago javascripthow to show 1 day ago in javascriptjavascript get day agojs time since datejavascript post created 1 min agohow to 1 day back from date in javesripttime ago script jsjavascript ago timejs date is minutes agojavascript hours and minutes and seconds agodate ago javascriptjs time agojs timeagroget day ago in javascropt1 day ago javascriptnodejs timestamp is 5 minutes agodisplay date time in hours ago or after javascriptjavascript how long ago was datehow to get days ago from current date in javascripttime to ago javascriptget 1 year ago date javascriptposted before 2 minits ago jsjs one day agohors ago to date formatjavascript get date for one day agohow to make days ago in javascriptget days ago from date javascriptjavascript date to days agojs get time agotimeago jsjs library that takes a date and converst to today 2c a few minutes ago 2c an hour ago 2c just nowjs date 1 year agotime agotimeago js configjavascript get date for days agojs date time agoget time 1 day ago javascripttime ago javascriptjs time ago functionget date 1 year ago javascripthow to calculate notification time like facebook reacttimeage javascripthour ago javascriptget date 10 days ago jsadd test for timeago javascriptimplementing timeago jshow to get 3 day ago in jsjs how many minutes agohow to make a whole number show up as 1 day ago in javascriptjavascript date set to one day agodate 1 day ago javascriptjavascript 1 day from nowjavascript date of one day agojs date convert 2 hours ago 2 days agoget day from 18 years ago javascripttimeago libraryjavascript time agohow to show 1 day ago in javascript