ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺦﯾﺭﺎﺗ ﯼﺎﻫ ﺵﻭﺭ


فهرست مطالب

    نمایش فهرست مطالب


new Date() ﻩﺪﻧﺯﺎﺳ

.ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ new Date() ﺎﺑ ﺦﯾﺭﺎﺗ ءﺎﯿﺷﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ

new Date() ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﯽﻠﻌﻓ ﻥﺎﻣﺯ ﻭ ﺦﯾﺭﺎﺗ ﺎﺑ ﺍﺭ ﺦﯾﺭﺎﺗ

ﺪﯿﻨﮐ ﺖﻓﺎﯾﺭﺩ ﺍﺭ ﯽﻠﻌﻓ ﻥﺎﻣﺯ

const date = new Date();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>Using new Date()</h2>
<p>Create a new date object with the current date and time:</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d;
</script>

</body>
</html>

ﺎﻫ ﺵﻭﺭ ﺖﻓﺎﯾﺭﺩ ﺦﯾﺭﺎﺗ

getFullYear()

(YYY) ﯽﻤﻗﺭ ﺭﺎﻬﭼ ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﻝﺎﺳ ﺖﻓﺎﯾﺭﺩ

getMonth()

(11-0) ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﻩﺎﻣ ﺖﻓﺎﯾﺭﺩ

getDate()

(31-1) ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺯﻭﺭ ﺖﻓﺎﯾﺭﺩ

getDay()

ﻪﺘﻔﻫ ﺯﻭﺭ (6-0) ﺪﯿﻨﮐ ﺖﻓﺎﯾﺭﺩ ﺩﺪﻋ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ

getHours()

(0-23)/>ﺖﻋﺎﺳ ﺖﻓﺎﯾﺭﺩ

getMinutes()

(0-59)/>ﻪﻘﯿﻗﺩ ﺖﻓﺎﯾﺭﺩ

getSeconds()

(0-59)/>ﻪﯿﻧﺎﺛ ﺖﻓﺎﯾﺭﺩ

getMilliseconds()

(0-999)/>ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ﺖﻓﺎﯾﺭﺩ

getTime()

(1970 ﻪﯾﻮﻧﺍﮊ 1 ﺯﺍ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ) ﻥﺎﻣﺯ ﺖﻓﺎﯾﺭﺩ

1 ﺖﺷﺍﺩﺩﺎﯾ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﯽﻠﺤﻣ ﻥﺎﻣﺯ ﻻﺎﺑ ﺖﻓﺎﯾﺭﺩ ﯼﺎﻫ ﺵﻭﺭ

ﯽﻧﺎﻬﺟ ﻥﺎﻣﺯ (UTC) ﺖﺳﺍ ﻩﺪﺷ ﺖﺒﺛ ﻪﺤﻔﺻ ﻦﯾﺍ ﻦﯿﯾﺎﭘ ﺭﺩ.

2 ﻩﺮﺼﺒﺗ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺩﻮﺟﻮﻣ ﺦﯾﺭﺎﺗ ءﺎﯿﺷﺍ ﺯﺍ ﺍﺭ ﺕﺎﻋﻼﻃﺍ get ﯼﺎﻫﺪﺘﻣ

.ﺖﺴﯿﻧ "ﺍﺮﺟﺍ ﻝﺎﺣ ﺭﺩ" "ﺖﻋﺎﺳ" .ﺖﺳﺍ ﺖﺑﺎﺛ ﻥﺎﻣﺯ ،ﺦﯾﺭﺎﺗ ءﯽﺷ ﺭﺩ

.ﺖﺴﯿﻧ ﻥﺎﺴﮑﯾ ﯽﻠﻌﻓ ﻥﺎﻣﺯ ﺎﺑ ﺦﯾﺭﺎﺗ ءﯽﺷ ﺭﺩ ﻥﺎﻣﺯ


getFullYear() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﯽﻤﻗﺭ ﺭﺎﻬﭼ ﺩﺪﻋ ﮏﯾ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﮏﯾ ﻝﺎﺳ getFu

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getFullYear();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getFullYear() Method</h2>
<p>Return the full year of a date object:</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25")
document.getElementById("demo").innerHTML = d.getFullYear();
</script>

</body>
</html>
const d = new Date();
d.getFullYear();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>The getFullYear() Method</h2>
<p>Return the full year of a date object:</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getFullYear();
</script>

</body>
</html>

!ﺭﺍﺪﺸﻫ

.ﺪﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ()getYear ﺩﺭﺍﺪﻧﺎﺘﺳﺍ ﺮﯿﻏ ﺪﺘﻣ ﺯﺍ ﺖﺳﺍ ﻦﮑﻤﻣ ﯽﻤﯾﺪﻗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺪﮐ

()getYear ﺪﻧﺍﺩﺮﮔﺮﺑ ﺍﺭ ﯽﻤﻗﺭ 2 ﻝﺎﺳ ﮏﯾ ﺖﺳﺍ ﺭﺍﺮﻗ.

getYear() ﺪﯿﻨﮑﻧ ﻩﺩﺎﻔﺘﺳﺍ ﻥﺁ ﺯﺍ .ﺖﺳﺍ ﻩﺪﺷ ﺥﻮﺴﻨﻣ!


getMonth() ﺵﻭﺭ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (11-0) ﺩﺪﻋ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﻩﺎﻣ getMonth()

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

... ،ﺖﺳﺍ 1 ﻩﺭﺎﻤﺷ ﻪﯾﺭﻮﻓ ،0 ﻩﺭﺎﻤﺷ ﻩﺎﻣ ﻪﯾﻮﻧﺍﮊ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ

.ﺖﺳﺍ 11 ﻩﺭﺎﻤﺷ ﻩﺎﻣ ﺮﺒﻣﺎﺳﺩ ،ﺖﯾﺎﻬﻧ ﺭﺩ

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getMonth();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getMonth() Method</h2>
<p>Return the month of a date as a number from 0 to 11.</p>
<p>To get the correct month number, you must add 1:</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getMonth() + 1;
</script>

</body>
</html>
const d = new Date();
d.getMonth();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getMonth() Method</h2>
<p>Return the month of a date as a number from 0 to 11.</p>
<p>To get the correct month number, you must add 1:</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getMonth() + 1;
</script>

</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﻧ ﻥﺍﻮﻨﻋ ﻪﺑ ﻩﺎﻣ ﻥﺪﻧﺍﺩﺮﮔﺮﺑ ﯼﺍﺮﺑ ﺎﻫ ﻡﺎﻧ ﺯﺍ ﯼﺍ ﻪﯾﺍﺭﺁ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﺎﻫ ﻝﺎﺜﻣ

const months = ["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"];

const d = new Date("2021-03-25");
let month = months[d.getMonth()];

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>JavaScript getMonth()</h2>
<p>Return the month as a number.</p>
<p>You can use an array of names to return the month as a name:</p>

<p id="demo"></p>

<script>
const months = ["January","February","March","April","May","June","July","August","September","October","November","December"];

const d = new Date("2021-03-25");
let month = months[d.getMonth()];
document.getElementById("demo").innerHTML = month;
</script>

</body>
</html>
const months = ["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"];

const d = new Date();
let month = months[d.getMonth()];

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>JavaScript getMonth()</h2>
<p>Return the month as a number.</p>
<p>You can use an array of names to return the month as a name:</p>

<p id="demo"></p>

<script>
const months = ["January","February","March","April","May","June","July","August","September","October","November","December"];

const d = new Date();
let month = months[d.getMonth()];
document.getElementById("demo").innerHTML = month;
</script>

</body>
</html>

getDate() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔﯽﻣﺮﺑ (31-1) ﺩﺪﻋ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﺯﻭﺭ getDate()<

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getDate();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getDate() Method</h2>
<p>Return the day of a date as a number (1-31):</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getDate();
</script>

</body>
</html>
const d = new Date();
d.getDate();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getDate() Method</h2>
<p>Return the day of a date as a number (1-31):</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getDate();
</script>

</body>
</html>


getHours() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (23-0) ﺩﺪﻋ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﮏﯾ ﺕﺎﻋﺎﺳ getHours(

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getHours();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getHours() Method</h2>
<p>Return the hours of a date as a number (0-23):</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");document.getElementById("demo").innerHTML = d.getHours();
</script>

</body>
</html>
const d = new Date();
d.getHours();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getHours() Method</h2>
<p>Return the hours of a date as a number (0-23):</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getHours();
</script>

</body>
</html>

getMinutes() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (59-0) ﺩﺪﻋ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﮏﯾ ﻪﻘﯿﻗﺩ getMinute

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getMinutes();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getMinutes() Method</h2>
<p>Returns the minutes of a date as a number (0-59):</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getMinutes();
</script>

</body>
</html>
const d = new Date();
d.getMinutes();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getMinutes() Method</h2>
<p>Returns the minutes of a date as a number (0-59):</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getMinutes();
</script>

</body>
</html>

getSeconds() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (59-0) ﺩﺪﻋ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﯼﺎﻫ ﻪﯿﻧﺎﺛ getSeco

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getSeconds();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getSeconds() Method</h2>
<p>Return the seconds of a date as a number (0-59):</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getSeconds();
</script>

</body>
</html>
const d = new Date();
d.getSeconds();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getSeconds() Method</h2>
<p>Return the seconds of a date as a number (0-59):</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getSeconds();
</script>

</body>
</html>

getMilliseconds() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (0-999) ﺩﺪﻋ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﮏﯾ ﯼﺎﻫ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getMilliseconds();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getMilliseconds() Method</h2>
<p>Return the milliseconds of a date as a number (0-999):</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getMilliseconds();
</script>

</body>
</html>
const d = new Date();
d.getMilliseconds();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getMilliseconds() Method</h2>
<p>Return the milliseconds of a date as a number (0-999):</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getMilliseconds();
</script>

</body>
</html>

getDay() ﺵﻭﺭ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (6-0) ﺩﺪﻋ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺦﯾﺭﺎﺗ ﮏﯾ ﻪﺘﻔﻫ ﺯﻭﺭ getDay(

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

.ﺖﺳﺍ ﻪﺒﻨﺸﮑﯾ (0 ﺯﻭﺭ) ﻪﺘﻔﻫ ﺯﻭﺭ ﻦﯿﻟﻭﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ

.ﺪﻨﻧﺍﺩ ﯽﻣ ﻪﺒﻨﺷﻭﺩ ﺍﺭ ﻪﺘﻔﻫ ﺯﻭﺭ ﻦﯿﻟﻭﺍ ﻥﺎﻬﺟ ﯼﺎﻫﺭﻮﺸﮐ ﺯﺍ ﯽﺧﺮﺑ

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("2021-03-25");
d.getDay();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getDay() Method</h2>
<p>Return the weekday as a number:</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getDay();
</script>

</body>
</html>
const d = new Date();
d.getDay();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getDay() Method</h2>
<p>Return the weekday as a number:</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getDay();
</script>

</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻡﺎﻧ ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﺘﻔﻫ ﯼﺎﻫﺯﻭﺭ ﻥﺪﻧﺍﺩﺮﮔﺮﺑ ﯼﺍﺮﺑ getDa

ﺎﻫ ﻝﺎﺜﻣ

const days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];

const d = new Date("2021-03-25");
let day = days[d.getDay()];

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getDay() Method</h2>
<p>Return the weekday as a number.</p>
<p>You can use an array of names to return the weekday as a name:</p>

<p id="demo"></p>

<script>
const days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

const d = new Date("2021-03-25");
let day = days[d.getDay()];
document.getElementById("demo").innerHTML = day;
</script>

</body>
</html>
const days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];

const d = new Date();
let day = days[d.getDay()];

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getDay() Method</h2>
<p>Return the weekday as a number.</p>
<p>You can use an array of names to return the weekday as a name:</p>

<p id="demo"></p>

<script>
const days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

const d = new Date();
let day = days[d.getDay()];
document.getElementById("demo").innerHTML = day;
</script>

</body>
</html>

getTime() ﺵﻭﺭ

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ 1970 ﻪﯾﻮﻧﺍﮊ ﻝﻭﺍ ﺯﺍ ﺍﺭ ﺎﻫ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ ﺩﺍﺪﻌﺗ getT

ﺎﻫ ﻝﺎﺜﻣ

const d = new Date("1970-01-01");
d.getTime();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getTime() Method</h2>
<p></p>
<p>Return the number of milliseconds since midnight January 1, 1970:</p>

<p id="demo"></p>

<script>
const d = new Date("1970-01-01");
document.getElementById("demo").innerHTML = d.getTime();
</script>

</body>
</html>
const d = new Date("2021-03-25");
d.getTime();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getTime() Method</h2>
<p></p>
<p>Return the number of milliseconds since midnight January 1, 1970:</p>

<p id="demo"></p>

<script>
const d = new Date("2021-03-25");
document.getElementById("demo").innerHTML = d.getTime();
</script>

</body>
</html>
const d = new Date();
d.getTime();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<h2>The getTime() Method</h2>
<p></p>
<p>Return the number of milliseconds since midnight January 1, 1970:</p>

<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getTime();
</script>

</body>
</html>

Date.now() ﺵﻭﺭ

Date.now() ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ 1970 ﻪﯾﻮﻧﺍﮊ ﻝﻭﺍ ﺯﺍ ﺍﺭ ﺎﻫ ﻪﯿﻧﺎ

ﺎﻫ ﻝﺎﺜﻣ

let ms = Date.now();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>The Date.now() Method</h2>
<p>Return the current date/time in milliseconds since January 1, 1970:</p>

<p id="demo"></p>

<script>
const date = Date.now();
document.getElementById("demo").innerHTML = date;
</script>

</body>
</html>

:1970/01/01 ﺯﺍ ﺲﭘ ﯼﺎﻬﻟﺎﺳ ﺩﺍﺪﻌﺗ ﻪﺒﺳﺎﺤﻣ

const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;

let years = Math.round(Date.now() / year);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>Using Date.now()</h2>
<p>Calculate the number of years since January 1, 1970:</p>

<p id="demo"></p>

<script>
// Calculate milliseconds in a year
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;

// Divide Date.now() with a year
let years = Math.round(Date.now() / year);
document.getElementById("demo").innerHTML = years;
</script>

</body>
</html>

Date.now() ﯽﺷ ﺯﺍ ﺖﺑﺎﺛ ﺵﻭﺭ ﮏﯾ Date ﺖﺳﺍ.

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ myDate.now() ﺪﻨﻧﺎﻣ ﺦﯾﺭﺎﺗ ءﯽﺷ ﮏﯾ ﺭﺩ ﺍﺭ

.ﺖﺳﺍ Date.now() ﻪﺸﯿﻤﻫ ﻮﺤﻧ


UTC ﺦﯾﺭﺎﺗ ﺖﻓﺎﯾﺭﺩ ﯼﺎﻫ ﺵﻭﺭ

getUTCDate() / getDate()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ UTC ﺦﯾﺭﺎﺗ

getUTCFullYear() / getFullYear()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ UTC ﻝﺎﺳ

getUTCMonth() / getMonth()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ UTC ﻩﺎﻣ

getUTCDay() / getDay()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ UTC ﺯﻭﺭ

getUTCHours() / getHours()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ UTC ﺖﻋﺎﺳ

getUTCMinutes() / getMinutes()

ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ UTC ﻪﻘﯿﻗﺩ

getUTCSeconds() / getSeconds()

UTC ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﯿﻧﺎﺛ

getUTCMilliseconds() / getMilliseconds()

UTC ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻪﯿﻧﺎﺛ ﯽﻠﯿﻣ

UTC methods use UTC time (Coordinated Universal Time).

UTC time is the same as GMT (Greenwich Mean Time).

The difference between Local time and UTC time can be up to 24 hours.






getTimezoneOffset() ﺵﻭﺭ

.ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ (ﻪﻘﯿﻗﺩ ﺪﻨﭼ ﺭﺩ) ﺍﺭ ﺕﻭﺎﻔﺗ getTimezoneOffset()

ﻝﺎﺜﻣ

let diff = d.getTimezoneOffset();

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>The getTimezoneOffset() Method</h2>

<p>The time zone difference in minutes is:</p>
<p id="demo"></p>

<script>
const d = new Date();
document.getElementById("demo").innerHTML = d.getTimezoneOffset();
</script>

</body>
</html>

ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺦﯾﺭﺎﺗ ﻊﺟﺮﻣ

:ﺪﯿﻨﮐ ﻪﻌﺟﺍﺮﻣ ﺎﻣ ﻪﺑ ،ﺦﯾﺭﺎﺗ ﻞﻣﺎﮐ ﻊﺟﺮﻣ ﮏﯾ ﯼﺍﺮﺑ

.ﻞﻣﺎﮐ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺦﯾﺭﺎﺗ ﻊﺟﺮﻣ

ﻭ ﺦﯾﺭﺎﺗ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻡﺎﻤﺗ ﺯﺍ ﯽﯾﺎﻫ ﻪﻧﻮﻤﻧ ﻭ ﺕﺎﺤﯿﺿﻮﺗ ﯼﻭﺎﺣ ﻊﺟﺮﻣ


تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024