JS implementation How many hours ago, how many days ago ...

Source: Internet
Author: User

Recently need to implement the function of the topic, because my timestamp is generated by PHP, so the conversion JS timestamp needs to multiply 1000, nonsense not to say, see the code below!

You can judge whether the value passed in is a numeric type, and whether it is larger than the current timestamp! Can be prompted according to the results of illegal parameters and so on!

1 functionGetdatediff (datetimestamp) {2         varminute = 1000 * 60;3         varhour = minute * 60;4         varDay = Hour * 24;5         varHalfamonth = Day * 15;6         varMonth = Day * 30;7 8         varnow =NewDate (). GetTime ();9         varDiffvalue = Now-Datetimestamp;Ten  One         varMONTHC =diffvalue/month; A         varWEEKC =diffvalue/(7*day); -         varDAYC =diffvalue/day; -         varHOURC =diffvalue/hour; the         varMinC =diffvalue/minute; -         if(hourc>=12){ -result = "Over"; -          } +          Else if(hourc>=1){ -result = parseint (HOURC) + "hours ago"; +          } A          Else if(minc>=1){ atresult = parseint (MinC) + "Minutes ago"; -}Else -result = "just published"; -         returnresult; -     } -  in     varTime = Getdatediff (' 1466555123000 '); -alert (time);

JS implementation How many hours ago, how many days ago ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.