Javascript - Lấy quý trong năm

Lấy quý trong năm

Viết một hàm JavaScript để lấy quý (1 đến 4) trong năm.

Mã nguồn:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JavaScript program to convert the letters of a given string  in alphabetical order.</title>
</head>
<script>
function quarter_of_the_year(date) 
  {
    var month = date.getMonth() + 1;
    return (Math.ceil(month / 3));
  }


document.write(quarter_of_the_year(new Date())+"<br/>");
document.write(quarter_of_the_year(new Date(2015, 1, 21))+"<br/>"); 
document.write(quarter_of_the_year(new Date(2015, 10, 18))+"<br/>");
</script>
<body>

</body>
</html> 

Xem ví dụ

Lưu đồ thuật toán:

Flowchart: JavaScript- Get the quarter  of the year


Chatbot Tư vấn Lộ trình CNTT 🤖
Chào bạn! Tôi có thể tư vấn về các lộ trình học CNTT dựa trên roadmap.w3typing.com. Hãy chọn một từ khóa dưới đây hoặc gõ câu hỏi của bạn (ví dụ: "Frontend", "Backend", "Python", "DevOps").