Announcement: On
November 13, 2024, all users will need to
use a Cloud project in order to access Earth Engine. After this date, continued individual access without a Cloud project will require
an exception.
ee.Date.getFraction
Returns this date's elapsed fraction of the specified unit (between 0 and 1).
Usage | Returns | Date.getFraction(unit, timeZone) | Float |
Argument | Type | Details | this: date | Date | |
unit | String | One of 'year', 'month' 'week', 'day', 'hour', 'minute', or 'second'. |
timeZone | String, default: null | The time zone (e.g., 'America/Los_Angeles'); defaults to UTC. |
Examples
Code Editor (JavaScript)
var date = ee.Date('2021-4-30T07:15:31.24');
print('Elapsed fraction of a year', date.getFraction('year'));
print('Elapsed fraction of a month', date.getFraction('month'));
print('Elapsed fraction of a week', date.getFraction('week'));
print('Elapsed fraction of a day', date.getFraction('day'));
print('Elapsed fraction of an hour', date.getFraction('hour'));
print('Elapsed fraction of a minute', date.getFraction('minute'));
print('Elapsed fraction of a second', date.getFraction('second'));
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
date = ee.Date('2021-4-30T07:15:31.24')
display('Elapsed fraction of a year:', date.getFraction('year'))
display('Elapsed fraction of a month:', date.getFraction('month'))
display('Elapsed fraction of a week:', date.getFraction('week'))
display('Elapsed fraction of a day:', date.getFraction('day'))
display('Elapsed fraction of an hour:', date.getFraction('hour'))
display('Elapsed fraction of a minute:', date.getFraction('minute'))
display('Elapsed fraction of a second:', date.getFraction('second'))
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["`Date.getFraction()` returns the elapsed fraction of a specified time unit (year, month, week, day, hour, minute, or second) for a given date."],["The returned value is a float between 0 and 1, representing the proportion of the specified unit that has elapsed."],["You can optionally specify a time zone; otherwise, it defaults to UTC."],["The function is available in both JavaScript and Python environments within Google Earth Engine."]]],[]]