Time functions

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

    #1

    Time functions


    I wish to generate a datetime string that has the following format.
    '05/02/2007 12:46'. The leading zeros are required.

    I found '14.2 time' in the library reference and have pulled in
    localtime. Are there any formatting functions available or do I need
    to make my own? Perhaps there is something similar to C's printf
    formatting.

    Thanks,

    jvh (whose newbieism is most glaring)

  • HMS Surprise

    #2
    Re: Time functions

    On May 2, 12:00 pm, HMS Surprise <j...@datavoice int.comwrote:
    I wish to generate a datetime string that has the following format.
    '05/02/2007 12:46'. The leading zeros are required.
    >
    I found '14.2 time' in the library reference and have pulled in
    localtime. Are there any formatting functions available or do I need
    to make my own? Perhaps there is something similar to C's printf
    formatting.
    >
    Thanks,
    >
    jvh (whose newbieism is most glaring)
    Oops, it appears I overlooked strftime.

    Regrets,

    jvh

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: Time functions

      In <1178125256.640 115.26480@o5g20 00hsb.googlegro ups.com>, HMS Surprise
      wrote:
      I wish to generate a datetime string that has the following format.
      '05/02/2007 12:46'. The leading zeros are required.
      >
      I found '14.2 time' in the library reference and have pulled in
      localtime. Are there any formatting functions available or do I need
      to make my own? Perhaps there is something similar to C's printf
      formatting.
      You mean like `time.strftime( )`!? :-)

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • HMS Surprise

        #4
        Re: Time functions

        On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
        In <1178125256.640 115.26...@o5g20 00hsb.googlegro ups.com>, HMS Surprise
        wrote:
        >
        I wish to generate a datetime string that has the following format.
        '05/02/2007 12:46'. The leading zeros are required.
        >
        I found '14.2 time' in the library reference and have pulled in
        localtime. Are there any formatting functions available or do I need
        to make my own? Perhaps there is something similar to C's printf
        formatting.
        >
        You mean like `time.strftime( )`!? :-)
        >
        Ciao,
        Marc 'BlackJack' Rintsch
        Thanks for posting.

        I think I have an import misconception.

        I use
        import from time localtime, strftime
        t = strftime('%m/%d/%Y %H:%M', localtime())

        This works. How would one use it with the module name pre-pended?

        thanx,
        jvh

        Comment

        • Matimus

          #5
          Re: Time functions

          On May 2, 10:21 am, HMS Surprise <j...@datavoice int.comwrote:
          On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
          >
          In <1178125256.640 115.26...@o5g20 00hsb.googlegro ups.com>, HMS Surprise
          wrote:
          >
          I wish to generate a datetime string that has the following format.
          '05/02/2007 12:46'. The leading zeros are required.
          >
          I found '14.2 time' in the library reference and have pulled in
          localtime. Are there any formatting functions available or do I need
          to make my own? Perhaps there is something similar to C's printf
          formatting.
          >
          You mean like `time.strftime( )`!? :-)
          >
          Ciao,
          Marc 'BlackJack' Rintsch
          >
          Thanks for posting.
          >
          I think I have an import misconception.
          >
          I use
          import from time localtime, strftime
          t = strftime('%m/%d/%Y %H:%M', localtime())
          >
          This works. How would one use it with the module name pre-pended?
          >
          thanx,
          jvh
          I would think that what you have written there shouldn't work at
          all...

          it would need to be:

          Code:
          from time import localtime, strftime
          to use the prepended module name just do this instead:

          Code:
          import time
          t = time.strftime('%m/%d/%Y %H:%M', time.localtime())

          Comment

          • Grant Edwards

            #6
            Re: Time functions

            On 2007-05-02, Matimus <mccredie@gmail .comwrote:
            >I think I have an import misconception.
            >>
            >I use
            > import from time localtime, strftime
            > t = strftime('%m/%d/%Y %H:%M', localtime())
            >>
            >This works. How would one use it with the module name pre-pended?
            >
            I would think that what you have written there shouldn't work at
            all...
            It doesn't.
            it would need to be:
            >
            Code:
            from time import localtime, strftime
            >
            to use the prepended module name just do this instead:
            >
            Code:
            import time
            t = time.strftime('%m/%d/%Y %H:%M', time.localtime())
            or just this

            t = time.strftime(' %m/%d/%Y %H:%M')

            time.strftime() has used the localtime() value by default for
            a while now.


            --
            Grant Edwards grante Yow! There's enough money
            at here to buy 5000 cans of
            visi.com Noodle-Roni!

            Comment

            Working...