Python Create unix timestamp five minutes in the future

2010-05-06T02:38:45

I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack.

def expires():
    '''return a UNIX style timestamp representing 5 minutes from now'''
    epoch = datetime.datetime(1970, 1, 1)
    seconds_in_a_day = 60 * 60 * 24
    five_minutes = datetime.timedelta(seconds=5*60)
    five_minutes_from_now = datetime.datetime.now() + five_minutes
    since_epoch = five_minutes_from_now - epoch
    return since_epoch.days * seconds_in_a_day + since_epoch.seconds

Is there a module or function that does the timestamp conversion for me?

Copyright License:
Author:「Daniel Rhoden」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/2775864/python-create-unix-timestamp-five-minutes-in-the-future

About “Python Create unix timestamp five minutes in the future” questions

I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack. def expires(): '''return a UNIX st...
I would like to know the best approach from the below solutions to calculate the time difference in minutes between the current Linux timestamp with the given epoch value (for example "1512082800"
I am wondering how to add time to a timestamp. The intention is to be able to get the current timestamp, add five minutes to it, then show the new one. I am trying to stop the output after five min...
I want to convert a DATETIME from a column to a UNIX TIMESTAMP. But the thing is that those dates are in a distant future, such as 2066-09-01... You can try those simple queries: SELECT UNIX_TIMES...
I have 2 dates, that I convert to UNIX timestamp - start date and confirm date. I subtract one from another and get numbers like these: -12643, 0, 3037, 1509, -3069 Basically, what I need to do i...
How can you convert the UNIX timestamp (that is in the form of a number denoting timestamp) into date, time(hours, minutes, seconds) in Objective-C?
Hey all! Ive got timezone troubles. I have a time stamp of 2010-07-26 23:35:03 What I really want to do is subtract 15 minutes from that time. My method was going to be a simple conversion to u...
I have a unix timestamp: 1368435600. And a duration in minutes: 75 for example. Using javascript I need to: Convert the timestamp to a string format hours:mins (09:00) Add n minutes to the timest...
I am trying to check if a user has logined 10 minutes ago or not . I have used the following query and last_login is in unix timestamp . But the following code i made also shows the result if the u...
This is how I'm getting my current UNIX timestamp. Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; How can I add on 10 minutes on this current UNIX

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.