javascript-get local time displayed in 12-hour system

Source: Internet
Author: User
Tags apm

<! DOCTYPE html>functionShijian () {varToday =NewDate (); varHH =today.gethours (); varMM =today.getminutes (); varSS =today.getseconds (); varDay =Today.getday (); varDate =today.getdate (); varYear =today.getfullyear (); varmonth = Today.getmonth () + 1; /*declares a variable to receive the converted string*/            varDayday; /*use switch to complete the conversion operation*/            Switch(day) { Case1: Dayday= "One";  Break;  Case2: Dayday= "Two";  Break;  Case3: Dayday= "three";  Break;  Case4: Dayday= "Four";  Break;  Case5: Dayday= "Five";  Break;  Case6: Dayday= "Six";  Break;  Case7: Dayday= "Day";  Break; }            /*declare am and PM to represent morning and afternoon respectively, since the time is set to 12-hour system, from the user's point of view, to provide convenience*/            varAPM = "PM"; varABM = "AM"; /*The time taken from the system is 24-hour, and we subtract 12 to convert it to 12-hour .*/            if(HH > 12) {                varnum = hh-12; document.getElementById ("ABC"). InnerHTML = "Current system time:" + "<br/><br/>" + year + "years" + month + "Month" + Date + "Day" + num + "when" + mm + "min" + SS + "SEC" + "&nbsp;" + "Week" + Dayday + "&nbsp;" + "&nbsp;" + APM + "<br/><br/>" + "Good afternoon!" Welcome to tb128!. "; } Else{document.getElementById ("ABC"). InnerHTML = "Current system time:" + "<br/><br/>" + year + "years" + month + "Month" + Date + "Day" + hh +  "When" + mm + "min" + ss + "seconds" + "&nbsp;" + "Week" + Dayday + "&nbsp;" + "&nbsp;" + ABM + "<br/><br/>" + "Good afternoon!" Welcome to tb128!. "; }        }        /*executes the Shijian () method once every 1000 milliseconds (1 seconds)*/SetInterval ("Shijian ()", 1000)    </script>

javascript-get local time displayed in 12-hour system

Related Article

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.