ee.Filter.date
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Lọc một bộ sưu tập theo phạm vi ngày. Ngày bắt đầu và ngày kết thúc có thể là Ngày, số
(được diễn giải là mili giây kể từ 1970-01-01T00:00:00Z) hoặc chuỗi (chẳng hạn như "1996-01-01T08:00"). Dựa trên thuộc tính "system:time_start".
Trả về bộ lọc đã tạo.
Cách sử dụng | Giá trị trả về |
---|
ee.Filter.date(start, end) | Lọc |
Đối số | Loại | Thông tin chi tiết |
---|
start | Ngày|Số|Chuỗi | Ngày bắt đầu (bao gồm cả ngày này). |
end | Date|Number|String, không bắt buộc | Ngày kết thúc (không bao gồm). Không bắt buộc. Nếu không được chỉ định, một phạm vi 1 mili giây bắt đầu từ "start" sẽ được tạo. |
Ví dụ
Trình soạn thảo mã (JavaScript)
// collection.filterDate is preferred.
// Constructed FeatureCollection representing a field site sampled at
// four different dates.
var geom = ee.Geometry.Point([-119.56, 37.67]);
var fc = ee.FeatureCollection([
ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-06-10')}),
ee.Feature(geom, {'prop': 11, 'system:time_start': ee.Date('2021-06-20')}),
ee.Feature(geom, {'prop': 19, 'system:time_start': ee.Date('2021-07-10')}),
ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-07-20')})
]);
// Filter the observations in July 2021.
print('Field site observations collection in July 2021',
fc.filter(ee.Filter.date('2021-07-01', '2021-08-01')));
// Alternative input formats.
var dateRange = ee.DateRange('2021-07-01', '2021-08-01');
print('ee.DateRange as an input',
fc.filter(ee.Filter.date(dateRange)));
print('Numbers (milliseconds since Unix epoch) as an input',
fc.filter(ee.Filter.date(1625875200000, 1626739200001)));
print('ee.Date objects as an input',
fc.filter(ee.Filter.date(ee.Date('2021-07-01'), ee.Date('2021-08-01'))));
Thiết lập Python
Hãy xem trang
Môi trường Python để biết thông tin về API Python và cách sử dụng geemap
cho quá trình phát triển tương tác.
import ee
import geemap.core as geemap
Colab (Python)
from pprint import pprint
# collection.filterDate is preferred.
# Constructed FeatureCollection representing a field site sampled at
# four different dates.
geom = ee.Geometry.Point([-119.56, 37.67])
fc = ee.FeatureCollection([
ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-06-10')}),
ee.Feature(geom, {'prop': 11, 'system:time_start': ee.Date('2021-06-20')}),
ee.Feature(geom, {'prop': 19, 'system:time_start': ee.Date('2021-07-10')}),
ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-07-20')})
])
# Filter the observations in July 2021.
print('Field site observations collection in July 2021:')
pprint(fc.filter(ee.Filter.date('2021-07-01', '2021-08-01')).getInfo())
# Alternative input formats.
date_range = ee.DateRange('2021-07-01', '2021-08-01')
pprint(fc.filter(ee.Filter.date(date_range)).getInfo())
print('Numbers (milliseconds since Unix epoch) as an input:')
pprint(fc.filter(ee.Filter.date(1625875200000, 1626739200001)).getInfo())
print('ee.Date objects as an input:')
pprint(
fc.filter(
ee.Filter.date(ee.Date('2021-07-01'), ee.Date('2021-08-01'))
).getInfo()
)
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003eee.Filter.date\u003c/code\u003e filters a collection by date range based on the \u003ccode\u003esystem:time_start\u003c/code\u003e property.\u003c/p\u003e\n"],["\u003cp\u003eThe start and end dates can be specified as Dates, numbers (milliseconds since 1970-01-01T00:00:00Z), or strings (like 'YYYY-MM-DDTHH:mm').\u003c/p\u003e\n"],["\u003cp\u003eThe end date is exclusive, and if omitted, a 1-millisecond range starting at the start date is used.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eee.Filter.date\u003c/code\u003e returns a filter that can be applied to a collection using the \u003ccode\u003efilter\u003c/code\u003e method.\u003c/p\u003e\n"]]],["The core functionality is filtering a collection based on a date range, using the `system:time_start` property. The `ee.Filter.date(start, end)` method facilitates this, accepting `start` and optional `end` arguments as Dates, numbers (milliseconds since 1970), or strings (e.g., '1996-01-01'). If `end` is omitted, a 1-millisecond range is created. The method returns a filter, allowing users to filter collections. The code shows various ways of using this filter.\n"],null,["# ee.Filter.date\n\n\u003cbr /\u003e\n\nFilter a collection by date range. The start and end may be Dates, numbers\n\n\u003cbr /\u003e\n\n(interpreted as milliseconds since 1970-01-01T00:00:00Z), or strings (such as '1996-01-01T08:00'). Based on 'system:time_start' property.\n\nReturns the constructed filter.\n\n| Usage | Returns |\n|----------------------------------|---------|\n| `ee.Filter.date(start, `*end*`)` | Filter |\n\n| Argument | Type | Details |\n|----------|--------------------------------|-------------------------------------------------------------------------------------------------------------|\n| `start` | Date\\|Number\\|String | The start date (inclusive). |\n| `end` | Date\\|Number\\|String, optional | The end date (exclusive). Optional. If not specified, a 1-millisecond range starting at 'start' is created. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// collection.filterDate is preferred.\n// Constructed FeatureCollection representing a field site sampled at\n// four different dates.\nvar geom = ee.Geometry.Point([-119.56, 37.67]);\nvar fc = ee.FeatureCollection([\n ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-06-10')}),\n ee.Feature(geom, {'prop': 11, 'system:time_start': ee.Date('2021-06-20')}),\n ee.Feature(geom, {'prop': 19, 'system:time_start': ee.Date('2021-07-10')}),\n ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-07-20')})\n]);\n\n// Filter the observations in July 2021.\nprint('Field site observations collection in July 2021',\n fc.filter(ee.Filter.date('2021-07-01', '2021-08-01')));\n\n// Alternative input formats.\nvar dateRange = ee.DateRange('2021-07-01', '2021-08-01');\nprint('ee.DateRange as an input',\n fc.filter(ee.Filter.date(dateRange)));\n\nprint('Numbers (milliseconds since Unix epoch) as an input',\n fc.filter(ee.Filter.date(1625875200000, 1626739200001)));\n\nprint('ee.Date objects as an input',\n fc.filter(ee.Filter.date(ee.Date('2021-07-01'), ee.Date('2021-08-01'))));\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\nfrom pprint import pprint\n\n# collection.filterDate is preferred.\n# Constructed FeatureCollection representing a field site sampled at\n# four different dates.\ngeom = ee.Geometry.Point([-119.56, 37.67])\nfc = ee.FeatureCollection([\n ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-06-10')}),\n ee.Feature(geom, {'prop': 11, 'system:time_start': ee.Date('2021-06-20')}),\n ee.Feature(geom, {'prop': 19, 'system:time_start': ee.Date('2021-07-10')}),\n ee.Feature(geom, {'prop': 10, 'system:time_start': ee.Date('2021-07-20')})\n])\n\n# Filter the observations in July 2021.\nprint('Field site observations collection in July 2021:')\npprint(fc.filter(ee.Filter.date('2021-07-01', '2021-08-01')).getInfo())\n\n# Alternative input formats.\ndate_range = ee.DateRange('2021-07-01', '2021-08-01')\npprint(fc.filter(ee.Filter.date(date_range)).getInfo())\n\nprint('Numbers (milliseconds since Unix epoch) as an input:')\npprint(fc.filter(ee.Filter.date(1625875200000, 1626739200001)).getInfo())\n\nprint('ee.Date objects as an input:')\npprint(\n fc.filter(\n ee.Filter.date(ee.Date('2021-07-01'), ee.Date('2021-08-01'))\n ).getInfo()\n)\n```"]]