javascript--Formatting the current time

Source: Internet
Author: User

1<!doctype html>234<meta charset= "UTF-8" >5<title>Document</title>6<script>7     functionFormat (date) {8         varDays=["Day", "one", "two", "three", "four", "five", "six";//Create array days: ["Day",..., "six"]9         varY=date.getfullyear ();//get year, save in YTen         varM=date.getmonth (+1);//get month, save in M in +1 Onem<10&& (m= "0" +m);//if m<10, it becomes 0+m. A         varD=date.getdate ();//get date, save in D -d<10&& (d= "0" +d);//if d<10, it becomes 0+d. -         varDay=days[date.getday ()];//get the week, and then get the kanji that corresponds to days, save in Day theConsole.log (y+ "year" +m+ "month" +d+ "Day Worship" +Day ); -          -         varH=date.gethours ();//get hours, save in H -         varam; +H>=12?am= "Afternoon": "Morning";//declare variable AM, if h>=12, assign value to "PM" otherwise assign to "Morning" -h>12&& (H-=12);//if h>12, let h-12 +h<10&& (h= "0" +h);//if h<10, it becomes 0+h. A         varM=date.getminutes ();//get minutes, save in M atm<10&& (m= "0" +m);//if m<10, it becomes 0+m. -         returny+ "Year" +m+ "month" +d+ "+day+" "+am+h+": "+m; -}//May 10, 2016 Tuesday afternoon 6:13 -Console.log (Format (NewDate ())); -</script> - in<body> -    to</body> +

javascript--Formatting the current time

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.