Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:45:40+00:00 2026-06-17T22:45:40+00:00

From what I’ve researched, it appears storing my timestamps as UTC (not native, full,

  • 0

From what I’ve researched, it appears storing my timestamps as UTC (not native, full, eg: 2013-01-29 02:11:11.151996+00:00) is the norm.

When retrieving the times, I want to check if a window of time has elapsed. So,

currentTime = datetime.utcnow()
storedTime  = '2013-01-29 02:11:11.151996+00:00'

if (storedTime + 60) > currentTime:
    print "60 or more has elapsed, do something again"

How can I add arbitrary amounts of time do a UTC timestamp, even if it’s not a datetime object? Or, how do I create a datetime object from a UTC timestamp, and then add arbirary time to it.

I know once I have two datetime objects I can do d1 > d2. I’m just having trouble getting the objects.

TIA!

Edit/Update:

Thanks everyone. I decided to do the following: (which is a combination of both answers, sorry I can only accept one!)

        lastTime = dateutil.parser.parse(subDict['last'])
        utcNow = datetime.datetime.utcnow().replace(tzinfo=tz.tzutc())

        if lastTime + datetime.timedelta(seconds=subDict['interval']) < utcNow:
            print "Time elapsed, do something!"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:45:42+00:00Added an answer on June 17, 2026 at 10:45 pm

    Put storedTime as a datetime object and add a timedelta. strptime is used to parse a string to a datetime object:

    (Refer to the link for the details of the format string)

    currentTime = datetime.datetime.utcnow()
    s = '2013-01-29 02:11:11.151996+00:00'
    storedTime = datetime.datetime.strptime(s[:-6], "%Y-%m-%d %H:%M:%S.%f")
    if storedTime + datetime.timedelta(minutes=60) > currentTime:
        print "stuff..."
    

    NOTE: from 3.7 .fromisoformat() was added, so there is no need to use strptime for isoformat() datetime strings.

    >>> datetime.datetime.fromisoformat('2013-01-29 02:11:11.151996+00:00')
    datetime.datetime(2013, 1, 29, 2, 11, 11, 151996, tzinfo=datetime.timezone.utc)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the Scala API , I got the following example, which does not compile;
from title it appears a stupid question :) i know but i have a
From first glance, it would appear I have two basic choices for storing ZIP
From my website, I have a button which calls a method and then generates
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
from Apple's Documentation : @property(readonly, nonatomic) CMMagneticField magneticField Returns the magnetic field measured by
From time to time, I find myself using the same group of statements and
from fabric.api import sudo, put, run def install(): run('source /home/user/.virtualenvs/demo/bin/activate') run('pip install requests') if
From 2.13.2/3 The double quote and the question mark ? , can be represented
From time to time I run into the issue that Grails integration tests the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.