--- title: Date.UTC() slug: Web/JavaScript/Reference/Global_Objects/Date/UTC tags: - تاريخ - جافاسكربت - طريقة - مرجع translation_of: Web/JavaScript/Reference/Global_Objects/Date/UTC ---
دالة Date.UTC()
تقبل نفس المُعاملات parameters علي الرغم من طول تكوين المنشيء، ويٌعيد التاريخ إلي المللي ثانية من بداية تاريخ 1 يناير, 1970, 00:00:00, التوقيت العالمي.
Date.UTC(year, month[, day[, hour[, minute[, second[, millisecond]]]]])
year
month
day
hour
minute
second
millisecond
رقم يمثل عدد المللي ثانية في التاريخ المحدد منذ 1 يناير, 1970, 00:00:00، التوقيت العالمي.
تقوم دالة UTC()
بأخذ معاملات (parameters) التاريخ المحددة بفاصلة ثم تُعيدها إلي مللي ثانية بين 1 يناير 1970، 00:00:00 التوقيت العالمي، والوقت الذي حددته.
يجب عليك تحديد السنة
كاملة؛ علي سبيل المثال, 1998. إذا كانت السنة محددة ما بين عام 0 و99، تقوم هذه الطريقة بتحويل السنه إلي سنه في القرن العشرين (1900 + سنة)
؛ علي سبيل المثال، إذا حددت 95، فسيتم أستخدام 1995.
تختلف طريقة UTC()
عن منشيء التاريخ بطريقتين.
Date.UTC()
التوقيت العالمي بدلاً من التوقيت المحلي.Date.UTC()
بإرجاع قمية الوقت إلي رقم بدلاً من إنشاء تاريخ.If a parameter you specify is outside of the expected range, the UTC()
method updates the other parameters to allow for your number. For example, if you use 15 for month, the year will be incremented by 1 (year + 1)
, and 3 will be used for the month.
Because UTC()
is a static method of {{jsxref("Date")}}, you always use it as Date.UTC()
, rather than as a method of a {{jsxref("Date")}} object you created.
Date.UTC()
في المثال التالي يقوم بإنشاء التاريخ بإستخدام UTC بدلاً من التوقيت المحلي:
var utcDate = new Date(Date.UTC(2018, 11, 1, 0, 0, 0));
Specification | Status | Comment |
---|---|---|
{{SpecName('ESDraft', '#sec-date.utc', 'Date.UTC')}} | {{Spec2('ESDraft')}} | |
{{SpecName('ES6', '#sec-date.utc', 'Date.UTC')}} | {{Spec2('ES6')}} | |
{{SpecName('ES5.1', '#sec-15.9.4.3', 'Date.UTC')}} | {{Spec2('ES5.1')}} | |
{{SpecName('ES1')}} | {{Spec2('ES1')}} | Initial definition. Implemented in JavaScript 1.0. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("javascript.builtins.Date.UTC")}}
Date.UTC
with fewer than two argumentsWhen providing less than two arguments to Date.UTC
, {{jsxref("NaN")}} is returned. This behavior is specified in ECMAScript 2017. Engines who weren't supporting this behavior, have been updated (see {{bug(1050755)}}, ecma-262 #642).
Date.UTC(); Date.UTC(1); // Safari: NaN // Chrome/Opera/V8: NaN // Firefox <54: non-NaN // Firefox 54+: NaN // IE: non-NaN // Edge: NaN