Chris Jakuc
09/29/2023, 4:25 PMMarvin
09/29/2023, 4:26 PMprefect.deployments.deployments.Deployment
object in Prefect doesn't inherently contain a human-readable time and timezone. However, if you're dealing with a FlowRun
object, you can get the start time of the flow run in a human-readable format with the start_time
attribute. This will be a datetime object, which you can format to your liking.
Here's an example:
python
from datetime import datetime
# Assuming `flow_run` is your FlowRun object
start_time = flow_run.start_time
# To get it in a human-readable string
start_time_str = datetime.strftime(start_time, "%Y-%m-%d %H:%M:%S")
print(start_time_str)
This will print the start time in the format "YYYY-MM-DD HHMMSS".
As for the timezone, the start_time
is in UTC. If you want to convert it to a different timezone, you can use the pytz
library. Here's an example of converting it to Eastern Time:
python
from datetime import datetime
import pytz
# Assuming `flow_run` is your FlowRun object
start_time = flow_run.start_time
# Convert to Eastern Time
eastern = pytz.timezone('US/Eastern')
start_time_eastern = start_time.astimezone(eastern)
# To get it in a human-readable string
start_time_str = datetime.strftime(start_time_eastern, "%Y-%m-%d %H:%M:%S %Z")
print(start_time_str)
This will print the start time in Eastern Time, in the format "YYYY-MM-DD HHMMSS TZ", where TZ is the timezone name.
Remember, though, that dealing with timezones can be tricky, especially when daylight saving time comes into play. So always double-check your results.