varminute = 1000 * 60;varhour = Minute *60;varDay = Hour *24;varWeek = Day * 7;varMonth = Day * 30;functionGettimer (stringtime) {varTime1 =NewDate (). GetTime ();//the current timestampConsole.log (time1); varTime2 = Date.parse (NewDate (StringTime));//time stamp of the specified timeConsole.log (time2); varTime = time1-time2; varresult =NULL; if(Time < 0) {alert ("The set time cannot be earlier than the current time!" "); }Else if(Time/month >= 1) {result = "published in" + parseint (time/month) + "month ago! "; }Else if(Time/week >= 1) {result = "published in" + parseint (Time/week) + "Weeks ago!" "; }Else if(Time/day >= 1) {result = "published in" + parseint (time/day) + "days ago! "; }Else if(Time/hour >= 1) {result = "published in" + parseint (time/hour) + "hour ago! "; }Else if(Time/minute >= 1) {result = "published in" + parseint (Time/minute) + "Minutes ago! "; }Else{result= "Just released!" "; } console.log (result);} Gettimer ("2015-07-20 15:21:12");
JS conversion timestamp is "just", "1 minutes Ago", "2 hours Ago" "1 days Ago" and other formats