علاقه مندان به جاوا اسکریپت

saalek110

Well-Known Member
تاریخ





JavaScript:
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Dates</h1>
<h2>Using new Date()</h2>
<p>new Date() without arguments, creates a 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>


 

saalek110

Well-Known Member

JavaScript Date Formats​



TypeExample
ISO Date"2015-03-25" (The International Standard)
Short Date"03/25/2015"
Long Date"Mar 25 2015" or "25 Mar 2015"



 
آخرین ویرایش:

saalek110

Well-Known Member

JavaScript Get Date Methods​



MethodDescription
getFullYear()Get year as a four digit number (yyyy)
getMonth()Get month as a number (0-11)
getDate()Get day as a number (1-31)
getDay()Get weekday as a number (0-6)
getHours()Get hour (0-23)
getMinutes()Get minute (0-59)
getSeconds()Get second (0-59)
getMilliseconds()Get millisecond (0-999)
getTime()Get time (milliseconds since January 1, 1970)
 

saalek110

Well-Known Member
چاپ سال




JavaScript:
<!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>


سال را می دهد

 

saalek110

Well-Known Member
چاپ ماه


JavaScript:
<!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>



عدد ۳ را می دهد.
 

saalek110

Well-Known Member
چاپ روز

JavaScript:
<!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>


 

saalek110

Well-Known Member
ساعت


JavaScript:
<!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>


 

saalek110

Well-Known Member



دقیقه

JavaScript:
<!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>

 

saalek110

Well-Known Member




ثانیه



JavaScript:
<!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>



 

saalek110

Well-Known Member
میلی ثانیه

JavaScript:
<!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>


 

saalek110

Well-Known Member
روز هفته ، دوشنبه سه شنبه


JavaScript:
<!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>

 

saalek110

Well-Known Member
اگر روز هفته را به شکل کلمه می خواهید نه عدد:
JavaScript:
<!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>


 

saalek110

Well-Known Member
تعداد ثانیه از ۱۹۷۰

JavaScript:
<!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>


 

saalek110

Well-Known Member
JavaScript:
<!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>

میلی ثانیه ها از ۱۹۷۰


 

saalek110

Well-Known Member

UTC Date Get Methods​

MethodSame AsDescription
getUTCDate()getDate()Returns the UTC date
getUTCFullYear()getFullYear()Returns the UTC year
getUTCMonth()getMonth()Returns the UTC month
getUTCDay()getDay()Returns the UTC day
getUTCHours()getHours()Returns the UTC hour
getUTCMinutes()getMinutes()Returns the UTC minutes
getUTCSeconds()getSeconds()Returns the UTC seconds
getUTCMilliseconds()getMilliseconds()Returns the UTC milliseconds
 

saalek110

Well-Known Member

این لینک صفحه تاریخ است. اگر می خواهید دقیق تر از من نگاه کنید این لینکش است.
 

saalek110

Well-Known Member

JavaScript Set Date Methods​



 

جدیدترین ارسال ها

بالا