Conversion Standard Time is timestamp:
return Date.parse (Datestr.replace (/-/gi,"/"));}
Calculate the time difference:
1 function Getdatediff (datetimestamp) {2 varminute = +* -;3 varhour = minute * -;4 varDay = Hour * -;5 varHalfamonth = Day * the;6 varMonth = Day * -;7 varYear = day *365;8 varnow =NewDate (). GetTime ();9 varDiffvalue = Now-Datetimestamp;Ten if(Diffvalue <0) {return; } One varYearc = Diffvalue/Year ; A varMONTHC = Diffvalue/month; - varWEEKC = Diffvalue/(7*Day ); - varDAYC = Diffvalue/Day ; the varHOURC = Diffvalue/hour; - varMinC = Diffvalue/minute; - if(Yearc >=1) { -result =""+ parseint (YEARC) +"years ago"; + } - if(MONTHC >=1) { +result =""+ parseint (MONTHC) +"months ago"; A } at Else if(WEEKC >=1) { -result =""+ parseint (WEEKC) +"weeks ago"; - } - Else if(Dayc >=1) { -result =""+ parseint (DAYC) +"days ago"; - } in Else if(Hourc >=1) { -result =""+ parseint (HOURC) +"hours ago"; to } + Else if(MinC >=1) { -result =""+ parseint (MinC) +"minutes ago"; the}Else *result ="just"; $ returnresult;Panax Notoginseng}
Ext.: http://caibaojian.com/timestamp.html
JS converted to a few days ago, a few hours ago, a few minutes ago ...