Display current time and countdown Based on javascript _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces the information about the current time and countdown Function Based on javascript. If you need it, you can refer to self-practice and share with you a piece of js native code.
The Date object is used to process the Date and time.
Date () returns the Date and time of the current day.
GetDate () returns a day (1 ~ 31 ).
GetDay () returns a day of a week from the Date object (0 ~ 6 ).
GetMonth () returns the month from the Date object (0 ~ 11 ).
GetFullYear () returns the year from the Date object in four digits.
Use the getFullYear () method instead of getYear.
GetHours () returns the hour of the Date object (0 ~ 23 ).
GetMinutes () returns the minute of the Date object (0 ~ 59 ).
GetSeconds () returns the number of seconds of the Date object (0 ~ 59 ).
GetMilliseconds () returns the millisecond (0 ~) of the Date object ~ 999 ).
GetTime () returns the number of milliseconds since January 1, January 1, 1970.
GetTimezoneOffset () returns the minute difference between the local time and Greenwich Mean Time (GMT.
GetUTCDate () returns the Day (1 ~ 31 ).
GetUTCDay () returns the day of the week (0 ~ 6 ).
GetUTCMonth () returns the month (0 ~ 11 ).
GetUTCFullYear () returns the four-digit year from the Date object based on the universal time.
GetUTCHours () returns the hour of the Date object based on the Universal Time (0 ~ 23 ).
GetUTCMinutes () returns the minute of the Date object based on the Universal Time (0 ~ 59 ).
GetUTCSeconds () returns the second of the Date object based on the Universal Time (0 ~ 59 ).
GetUTCMilliseconds () returns the millisecond (0 ~ 999 ).
Parse () returns the number of milliseconds from midnight, January 1, January 1, 1970 to the specified date (string.
SetDate () sets a day of the month in the Date object (1 ~ 31 ).
SetMonth () sets the month (0 ~) in the Date object ~ 11 ).
SetFullYear () sets the year (four digits) in the Date object ).
Use the setFullYear () method instead of setYear.
SetHours () sets the hour (0 ~) in the Date object ~ 23 ).
SetMinutes () sets the minute (0 ~ 59 ).
SetSeconds () sets the second (0 ~) in the Date object ~ 59 ).
SetMilliseconds () sets the millisecond (0 ~) in the Date object ~ 999 ).
SetTime () sets the Date object in milliseconds.
SetUTCDate () sets the day of the month in the Date object based on the Universal Time (1 ~ 31 ).
SetUTCMonth () sets the month (0 ~ 11 ).
SetUTCFullYear () sets the year (four digits) in the Date object based on the universal time ).
SetUTCHours () sets the hour (0 ~ 23 ).
SetUTCMinutes () sets the minute (0 ~ 59 ).
SetUTCSeconds () sets the second (0 ~) in the Date object based on the universal time ~ 59 ).
SetUTCMilliseconds () sets the millisecond (0 ~ 999 ).
ToSource () returns the source code of the object.
ToString () converts a Date object to a string.
ToTimeString () converts the time part of the Date object to a string.
ToDateString () converts the Date part of the Date object to a string.
Use the toUTCString () method instead of toGMTString.
ToUTCString () converts a Date object to a string based on the universal time.
ToLocaleString () converts a Date object to a string based on the local time format.
ToLocaleTimeString () converts the time part of the Date object to a string based on the local time format.
ToLocaleDateString () converts the Date part of the Date object to a string based on the local time format.
UTC () returns the number of milliseconds from January 1, January 1, 1970 to the specified date based on the universal time.
ValueOf () returns the original value of the Date object.
Specific implementation code:

  
   
   Native js current time countdown code  Script window. onload = function () {getMyTime (); getMyTime1 ();} // 1. Add 0 function p (n) {return n <10? '0' + n: n;} // 2. countDown function getMyTime () {var startDate = new Date (); var endDate = new Date ('2017/17 11:15:00 '); var countDown = (endDate. getTime ()-startDate. getTime ()/1000; var day = parseInt (countDown/(24*60*60); var h = parseInt (countDown/(60*60) % 24 ); var m = parseInt (countDown/60% 60); var s = parseInt (countDown % 60); document. getElementById ('time '). innerHTML = day + 'day' + p (h) + 'hour '+ p (m) + 'minute' + p (s) + 'second '; setTimeout ('getmytime () ', 500); if (countDown <= 0) {document. getElementById ('time '). innerHTML = 'activity termination';} // 3. current Time function getMyTime1 () {var myDate = new Date (); var year = myDate. getFullYear (); var month = myDate. getMonth () + 1; var day = myDate. getDate (); var week = myDate. getDay (); var array = ['sunday', 'monday', 'tues', 'wedday', 'thurs', 'Friday', 'satur',]; var hour = myDate. getHours (); var minute = myDate. getMinutes (); var second = myDate. getSeconds (); document. getElementById ('time1 '). innerHTML = year + 'Year' + month + 'month' + day + 'day' + ''+ array [week] +'' + p (hour) + ': '+ p (minute) +': '+ p (second); setTimeout ('getmytime1 ()', 500);} script  

Countdown time:

Current Time:

The above is all the content of this article, and I hope it will help you learn javascript programming.

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.