How to calculate two time?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lookon

    How to calculate two time?

    I have two string like "2007-03-27T08:54:43+08: 00 "
    how do I get the hours between these two time(string format)?
  • skip@pobox.com

    #2
    Re: How to calculate two time?


    lookonI have two string like "2007-03-27T08:54:43+08: 00 " how do I get
    lookonthe hours between these two time(string format)?

    Look in PyPI for dateutil, then:
    >>import dateutil.parser
    >>t1 = dateutil.parser .parse("2007-03-27T08:54:43+08: 00")
    >>t1
    datetime.dateti me(2007, 3, 27, 8, 54, 43, tzinfo=tzoffset (None, 28800))
    >>t2 = dateutil.parser .parse("2007-03-29T10:00:00+02: 00") >>t2
    datetime.dateti me(2007, 3, 29, 10, 0, tzinfo=tzoffset (None, 7200))
    >>t2 - t1
    datetime.timede lta(2, 25517)

    Skip

    Comment

    • lookon

      #3
      Re: How to calculate two time?

      Thank you for your help.It works.

      However, I am using Google App Engine and cannot import dateutil and
      epsilon.

      Are there any other ways?


      On Oct 8, 10:06 pm, s...@pobox.com wrote:
          lookonI have two string like "2007-03-27T08:54:43+08: 00 " how do I get
          lookonthe hours between these two time(string format)?
      >
      Look in PyPI for dateutil, then:
      >
          >>import dateutil.parser
          >>t1 = dateutil.parser .parse("2007-03-27T08:54:43+08: 00")
          >>t1
          datetime.dateti me(2007, 3, 27, 8, 54, 43, tzinfo=tzoffset (None,28800))
          >>t2 = dateutil.parser .parse("2007-03-29T10:00:00+02: 00") >>>t2
          datetime.dateti me(2007, 3, 29, 10, 0, tzinfo=tzoffset (None, 7200))
          >>t2 - t1
          datetime.timede lta(2, 25517)
      >
      Skip

      Comment

      • skip@pobox.com

        #4
        Re: How to calculate two time?


        lookonThank you for your help.It works. However, I am using Google
        lookonApp Engine and cannot import dateutil and epsilon.

        I don't know how Google App Engine works, but are you not able to install
        pure Python modules?

        lookonAre there any other ways?

        Take a look at the time.strptime function to generate a tuple, then use

        t = time.strptime(t imestamp, format)
        t1 = datetime.dateti me(*t[0:6])

        Note that with this solution you will have to handle the timezone offset
        yourself.

        Skip

        Comment

        • lookon

          #5
          Re: How to calculate two time?

          but can you tell me what format is it?

          in the str there is a float and I can not deal with it
          On Oct 9, 7:20 pm, s...@pobox.com wrote:
              lookonThank you for your help.It works.  However, I am using Google
              lookonApp Engine and cannot import dateutil and epsilon.
          >
          I don't know how Google App Engine works, but are you not able to install
          pure Python modules?
          >
              lookonAre there any other ways?
          >
          Take a look at the time.strptime function to generate a tuple, then use
          >
              t = time.strptime(t imestamp, format)
              t1 = datetime.dateti me(*t[0:6])
          >
          Note that with this solution you will have to handle the timezone offset
          yourself.
          >
          Skip

          Comment

          • lookon

            #6
            Re: How to calculate two time?

            I have solved the problem. thank you

            On Oct 9, 7:20 pm, s...@pobox.com wrote:
                lookonThank you for your help.It works.  However, I am using Google
                lookonApp Engine and cannot import dateutil and epsilon.
            >
            I don't know how Google App Engine works, but are you not able to install
            pure Python modules?
            >
                lookonAre there any other ways?
            >
            Take a look at the time.strptime function to generate a tuple, then use
            >
                t = time.strptime(t imestamp, format)
                t1 = datetime.dateti me(*t[0:6])
            >
            Note that with this solution you will have to handle the timezone offset
            yourself.
            >
            Skip

            Comment

            • skip@pobox.com

              #7
              Re: How to calculate two time?


              lookonbut can you tell me what format is it?

              Read the strftime man page on your computer or Google for strftime or read
              the Python docs about the time.strftime function. (strftime and strptime
              strive to have the same set of format characters.)

              Skip

              Comment

              Working...