Cấp bậc tác giả:

HTML

Ngày đếm ngược

Được viết bởi QuangIT ngày 17/04/2013 lúc 08:13 PM
Hiệu ứng dựa vào ngày hệ thống để đếm ngược số ngày còn lại của năm hiện tại.
  • 0
  • 6697

Ngày đếm ngược

Hiệu ứng dựa vào ngày hệ thống để đếm ngược số ngày còn lại của năm hiện tại.

JavaScript:


<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function days_between(date1, date2) {

  // The number of milliseconds in one day

  var ONE_DAY = 1000 * 60 * 60 * 24


  // Convert both dates to milliseconds

  var date1_ms = date1.getTime()

  var date2_ms = date2.getTime()


  // Calculate the difference in milliseconds

  var difference_ms = Math.abs(date1_ms - date2_ms)

 

  // Convert back to days and return

  return Math.round(difference_ms/ONE_DAY)

}

//  End -->

</script>


HTML:


<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

// Store the current date and time

var current_date = new Date()


// Store the date of the next New Year's Day

var new_years_date = new Date()

new_years_date.setYear(new_years_date.getFullYear() + 1)

new_years_date.setMonth(0)

new_years_date.setDate(1)


// Call the days_between function

var days_left = days_between(current_date, new_years_date)


// Write the result to the page

if (days_left > 1) {

  document.write("<b>There are " + days_left + " days left this year.</b>")

}

else {

  document.write("<b>There is " + days_left + " day left this year.</b>")

}

//  End -->

</script>

Nguồn bài viết: Sưu tầm

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML