Home > Mobile >  Today's date in utc formatted in epoch
Today's date in utc formatted in epoch

Time:05-12

I need to use utc epoch to match the correct Stackoverflow API values and the API uses the date without time as a filter parameter.

See the example on final to this page:
https://api.stackexchange.com/docs/no-answer-questions#fromdate=2022-05-11&order=desc&sort=creation&filter=default&site=stackoverflow&run=true

I tried converting via .timestamp():

date_today = datetime.utcnow().date()
date_final = date_today.timestamp()

But this error appeared:

AttributeError: 'datetime.date' object has no attribute 'timestamp'

How should I proceed if timestamp only works for the complete value with date and time?

CodePudding user response:

datetime.utcnow().timestamp() gives a float value, e.g. 1652300340.219999.

For the StackOverflow API, you need to use an integer. You could use round(datetime.utcnow().timestamp()) to get the closest integer to the current UTC time.

  • Related