blob: ff6379db6048ca94e96d032f1efe4309016bc0dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
---
title: Date.now() | دالة الوقت الآن
slug: Web/JavaScript/Reference/Global_Objects/Date/now
tags:
- Date
- التاريخ
- الوقت
- جافاسكربت
- دالة
- دليل
- طريقة بديلة
- مرجع
translation_of: Web/JavaScript/Reference/Global_Objects/Date/now
---
<div>{{JSRef}}</div>
<p>تقوم دالة <strong><code>Date.now()</code></strong> بعرض عدد الثواني التي مضت منذ بداية احتساب الوقت بطريقة Timestamp وهو الأول من يناير عام 1970 الساعة الثانية عشر منتصف الليل تمامًا (First of January 1970 00:00:00) بتوقيت UTC.</p>
<h2 id="بنية_الجملة">بنية الجملة</h2>
<pre class="syntaxbox"><code>var timeInMs = Date.now();</code></pre>
<h3 id="القيمة_الراجعة">القيمة الراجعة</h3>
<p>القيمة الراجعة من هذه الدالة ستكون عبارة عن رقم {{jsxref("Number")}}، هذا الرقم يشير إلى عدد الثواني التي انقضت منذ بداية احتساب الوقت بطريقة TimeStamp بالأنظمة التي تستند إلى UNIX.</p>
<h2 id="الوصف">الوصف</h2>
<p>لإن دالة <code>now()</code> تقوم بإرجاع قيمة ثابتة من الوقت {{jsxref("Date")}} فيجب عليك استخدامها بهذا الشكل <code>Date.now()</code> .</p>
<h2 id="طريقة_احتياطية_(Polyfill)">طريقة احتياطية (Polyfill)</h2>
<p>تم اعتماد هذه الدالة في إصدار ECMA-262 5<sup>th</sup> المحركات التي لم يتم تحديثها لتدعم هذه الدالة يمكنها أن تحاكي دالة <code>Date.now()</code> عبر استخدام هذه الشيفرة البرمجية، هذه الشيفرة ستسمح للمتصفحات بأن تحاكي وظيفة هذه الدالة في حالة عدم دعمها لها :</p>
<pre class="brush: js">if (!Date.now) { // إذا لم تكن الدالة موجودة
Date.now = function now() { // قم بإنشاء الدالة
return new Date().getTime(); // واربطها بالوقت الحالي
};
}
</pre>
<h2 id="الخصائص">الخصائص</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">الخاصية</th>
<th scope="col">الحالة</th>
<th scope="col">تعليقات</th>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.9.4.4', 'Date.now')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td>Initial definition. Implemented in JavaScript 1.5.</td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-date.now', 'Date.now')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-date.now', 'Date.now')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="دعم_المتصفحات">دعم المتصفحات</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("javascript.builtins.Date.now")}}</p>
<h2 id="اقرأ_أيضًا">اقرأ أيضًا</h2>
<ul>
<li>{{domxref("Performance.now()")}} — provides timestamps with sub-millisecond resolution for use in measuring web page performance</li>
<li>{{domxref("console.time()")}} / {{domxref("console.timeEnd()")}}</li>
</ul>
|