إشعار: يجب
إثبات أهلية جميع المشاريع غير التجارية المسجّلة لاستخدام Earth Engine قبل
15 أبريل 2025 من أجل الحفاظ على إمكانية الوصول إلى Earth Engine.
ee.Date.difference
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تعرض هذه الدالة الفرق بين تاريخَين بالوحدات المحدّدة، وتكون النتيجة بفاصل عشري وتستند إلى متوسط طول الوحدة.
الاستخدام | المرتجعات |
---|
Date.difference(start, unit) | عدد عائم |
الوسيطة | النوع | التفاصيل |
---|
هذا: date | التاريخ | |
start | التاريخ | |
unit | سلسلة | تكون إمّا "عام" أو "شهر" أو "أسبوع" أو "يوم" أو "ساعة" أو "دقيقة" أو "ثانية". |
أمثلة
محرِّر الرموز البرمجية (JavaScript)
// Demonstrates the ee.Date.difference method.
var DATE_1 = ee.Date('2020-01-01');
var DATE_2 = ee.Date('2020-01-15');
var diff_1 = DATE_2.difference(DATE_1, 'days');
var diff_2 = DATE_1.difference(DATE_2, 'weeks');
print('The difference between ',
DATE_2,
' relative to ',
DATE_1,
' is ',
diff_1,
' days.');
print('The difference between ',
DATE_1,
' relative to ',
DATE_2,
' is ',
diff_2,
' weeks.');
إعداد Python
اطّلِع على صفحة
بيئة Python للحصول على معلومات عن واجهة برمجة التطبيقات Python API واستخدام
geemap
للتطوير التفاعلي.
import ee
import geemap.core as geemap
Colab (Python)
DATE_1 = ee.Date('2020-01-01')
DATE_2 = ee.Date('2020-01-15')
# Format the dates as strings.
t1 = DATE_1.format('YYYY-MM-DD').getInfo()
t2 = DATE_2.format('YYYY-MM-DD').getInfo()
# Calculate the differences between dates.
diff_1 = DATE_2.difference(DATE_1, 'days').getInfo()
diff_2 = DATE_1.difference(DATE_2, 'weeks').getInfo()
print(f'The difference between {t2} relative to {t1} is {diff_1} days.')
print(f'The difference between {t1} relative to {t2} is {diff_2} weeks.')
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003e\u003ccode\u003eDate.difference()\u003c/code\u003e calculates the difference between two dates, returning a floating-point number.\u003c/p\u003e\n"],["\u003cp\u003eThe difference is calculated based on the average length of the specified unit (e.g., 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second').\u003c/p\u003e\n"],["\u003cp\u003eThe function takes two \u003ccode\u003eee.Date\u003c/code\u003e objects as input, representing the start and end points for the calculation.\u003c/p\u003e\n"],["\u003cp\u003eThe result is relative to the first date and can be positive or negative depending on the order of the dates.\u003c/p\u003e\n"]]],["`Date.difference` calculates the difference between two dates, returning a floating-point number based on the average length of the specified unit. The function takes a `start` date and a `unit` string ('year', 'month', 'week', 'day', 'hour', 'minute', or 'second') as arguments. The output represents the difference in the chosen unit. Examples show calculating differences in days and weeks between two dates, showcasing both JavaScript and Python implementations.\n"],null,["# ee.Date.difference\n\nReturns the difference between two Dates in the specified units; the result is floating-point and based on the average length of the unit.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------------------|---------|\n| Date.difference`(start, unit)` | Float |\n\n| Argument | Type | Details |\n|--------------|--------|-----------------------------------------------------------------------|\n| this: `date` | Date | |\n| `start` | Date | |\n| `unit` | String | One of 'year', 'month', 'week', 'day', 'hour', 'minute', or 'second'. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Demonstrates the ee.Date.difference method.\n\nvar DATE_1 = ee.Date('2020-01-01');\nvar DATE_2 = ee.Date('2020-01-15');\n\nvar diff_1 = DATE_2.difference(DATE_1, 'days');\nvar diff_2 = DATE_1.difference(DATE_2, 'weeks');\n\nprint('The difference between ',\n DATE_2,\n ' relative to ',\n DATE_1,\n ' is ',\n diff_1,\n ' days.');\n\nprint('The difference between ',\n DATE_1,\n ' relative to ',\n DATE_2,\n ' is ',\n diff_2,\n ' weeks.');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nDATE_1 = ee.Date('2020-01-01')\nDATE_2 = ee.Date('2020-01-15')\n\n# Format the dates as strings.\nt1 = DATE_1.format('YYYY-MM-DD').getInfo()\nt2 = DATE_2.format('YYYY-MM-DD').getInfo()\n\n# Calculate the differences between dates.\ndiff_1 = DATE_2.difference(DATE_1, 'days').getInfo()\ndiff_2 = DATE_1.difference(DATE_2, 'weeks').getInfo()\n\nprint(f'The difference between {t2} relative to {t1} is {diff_1} days.')\nprint(f'The difference between {t1} relative to {t2} is {diff_2} weeks.')\n```"]]