Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102061 > unrolled thread

How do I add 18 seconds ISO-8301 String in Python?

Started byRobert James Liguori <gliesian66@gmail.com>
First post2016-01-23 16:54 -0800
Last post2016-01-24 16:26 +1100
Articles 7 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  How do I add 18 seconds ISO-8301 String in Python? Robert James Liguori <gliesian66@gmail.com> - 2016-01-23 16:54 -0800
    Re: How do I add 18 seconds to an ISO-8601 String in Python? Ben Finney <ben+python@benfinney.id.au> - 2016-01-24 12:55 +1100
      Re: How do I add 18 seconds to an ISO-8601 String in Python? Robert James Liguori <gliesian66@gmail.com> - 2016-01-23 18:01 -0800
      Re: How do I add 18 seconds to an ISO-8601 String in Python? Robert James Liguori <gliesian66@gmail.com> - 2016-01-23 18:03 -0800
      Re: How do I add 18 seconds to an ISO-8601 String in Python? Robert James Liguori <gliesian66@gmail.com> - 2016-01-23 18:22 -0800
        Re: How do I add 18 seconds to an ISO-8601 String in Python? Michael Torrie <torriem@gmail.com> - 2016-01-23 19:44 -0700
        Re: How do I add 18 seconds to an ISO-8601 String in Python? Ben Finney <ben+python@benfinney.id.au> - 2016-01-24 16:26 +1100

#102061 — How do I add 18 seconds ISO-8301 String in Python?

FromRobert James Liguori <gliesian66@gmail.com>
Date2016-01-23 16:54 -0800
SubjectHow do I add 18 seconds ISO-8301 String in Python?
Message-ID<8de7de19-9746-48f3-bded-d8bfb5c7dc22@googlegroups.com>
How do I add 18 seconds to this string in Python?

2000-01-01T16:36:25.000Z

[toc] | [next] | [standalone]


#102062 — Re: How do I add 18 seconds to an ISO-8601 String in Python?

FromBen Finney <ben+python@benfinney.id.au>
Date2016-01-24 12:55 +1100
SubjectRe: How do I add 18 seconds to an ISO-8601 String in Python?
Message-ID<mailman.191.1453600551.15297.python-list@python.org>
In reply to#102061
Robert James Liguori <gliesian66@gmail.com> writes:

(I've corrected the Subject field. The standard you're referring to is
ISO 8601, I believe.)

> How do I add 18 seconds to this string in Python?
>
> 2000-01-01T16:36:25.000Z

Two separate parts:

* How do I get a timestamp object from a text representation in ISO 8601
  format?

* How do I add 18 seconds to a timestamp object?

Parsing a text representation of a timestamp to get a timestamp object
is done with ‘datetime.strptime’ from the Python standard library
<URL:https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime>::

    >>> import datetime
    >>> foo_timestamp_text = "2000-01-01T16:36:25.000Z"
    >>> iso8601_format = "%Y-%m-%dT%H:%M:%S.%fZ"
    >>> foo_timestamp = datetime.datetime.strptime(foo_timestamp_text, iso8601_format)
    >>> foo_timestamp
    datetime.datetime(2000, 1, 1, 16, 36, 25)

Arithmetic on timestamps is done using the ‘datetime.timedelta’ type
<URL:https://docs.python.org/3/library/datetime.html#timedelta-objects>::

    >>> increment = datetime.timedelta(seconds=18)
    >>> increment
    datetime.timedelta(0, 18)
    >>> foo_timestamp + increment
    datetime.datetime(2000, 1, 1, 16, 36, 43)

-- 
 \        “You don't change the world by placidly finding your bliss — |
  `\        you do it by focusing your discontent in productive ways.” |
_o__)                                       —Paul Z. Myers, 2011-08-31 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#102063 — Re: How do I add 18 seconds to an ISO-8601 String in Python?

FromRobert James Liguori <gliesian66@gmail.com>
Date2016-01-23 18:01 -0800
SubjectRe: How do I add 18 seconds to an ISO-8601 String in Python?
Message-ID<04dcb7be-7d60-4439-9a05-24facbea8ac0@googlegroups.com>
In reply to#102062
I cant thank you enough!!!!

[toc] | [prev] | [next] | [standalone]


#102064 — Re: How do I add 18 seconds to an ISO-8601 String in Python?

FromRobert James Liguori <gliesian66@gmail.com>
Date2016-01-23 18:03 -0800
SubjectRe: How do I add 18 seconds to an ISO-8601 String in Python?
Message-ID<44005c99-fe69-4782-a098-a151af4864e7@googlegroups.com>
In reply to#102062
Oh... How do I convert it back to ISO 8301?

[toc] | [prev] | [next] | [standalone]


#102065 — Re: How do I add 18 seconds to an ISO-8601 String in Python?

FromRobert James Liguori <gliesian66@gmail.com>
Date2016-01-23 18:22 -0800
SubjectRe: How do I add 18 seconds to an ISO-8601 String in Python?
Message-ID<7a830b9e-4acc-49ea-9863-498163a20a5f@googlegroups.com>
In reply to#102062
Thank you so much!  Btw, how do I convert back to ISO-8301?

[toc] | [prev] | [next] | [standalone]


#102066 — Re: How do I add 18 seconds to an ISO-8601 String in Python?

FromMichael Torrie <torriem@gmail.com>
Date2016-01-23 19:44 -0700
SubjectRe: How do I add 18 seconds to an ISO-8601 String in Python?
Message-ID<mailman.192.1453603490.15297.python-list@python.org>
In reply to#102065
On 01/23/2016 07:22 PM, Robert James Liguori wrote:
> Thank you so much!  Btw, how do I convert back to ISO-8301?

Have a look at the documentation for the datetime module.  The docs will
tell you how you can convert to a string, formatted to your
specifications and needs.  As always, the documentation should be the
first place you look, followed by internet searches.

[toc] | [prev] | [next] | [standalone]


#102069 — Re: How do I add 18 seconds to an ISO-8601 String in Python?

FromBen Finney <ben+python@benfinney.id.au>
Date2016-01-24 16:26 +1100
SubjectRe: How do I add 18 seconds to an ISO-8601 String in Python?
Message-ID<mailman.195.1453613173.15297.python-list@python.org>
In reply to#102065
Robert James Liguori <gliesian66@gmail.com> writes:

> Thank you so much!  Btw, how do I convert back to ISO-8301?

You are consistently referring to “ISO 8301”, but I am confident that
you are not intending to talk about:

    ISO 8301: Thermal insulation -- Determination of steady-state
    thermal resistance and related properties -- Heat flow meter
    apparatus
    <URL:http://www.iso.org/iso/catalogue_detail.htm?csnumber=15421>

Please take care to refer to the correct standard code for the standard
you're referencing :-)

-- 
 \     “You say I took the name in vain / I don't even know the name / |
  `\    But if I did, well, really, what's it to you?” —Leonard Cohen, |
_o__)                                                     _Hallelujah_ |
Ben Finney

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web