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


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

Re: modification time in Python - Django: datetime != datetime :-(

Started byJaap van Wingerde <mailinglists@vanwingerde.nl>
First post2014-03-03 14:28 +0000
Last post2014-03-04 12:43 -0500
Articles 6 — 4 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: modification time in Python - Django: datetime != datetime :-( Jaap van Wingerde <mailinglists@vanwingerde.nl> - 2014-03-03 14:28 +0000
    Re: modification time in Python - Django: datetime != datetime :-( donarb <donarb@nwlink.com> - 2014-03-03 12:22 -0800
      Re: modification time in Python - Django: datetime != datetime :-( Chris Angelico <rosuav@gmail.com> - 2014-03-04 08:11 +1100
      Re: modification time in Python - Django: datetime != datetime :-( Jaap van Wingerde <mailinglists@vanwingerde.nl> - 2014-03-04 10:33 +0000
        Re: modification time in Python - Django: datetime != datetime :-( donarb <donarb@nwlink.com> - 2014-03-04 08:45 -0800
          Re: modification time in Python - Django: datetime != datetime :-( Roy Smith <roy@panix.com> - 2014-03-04 12:43 -0500

#67554 — Re: modification time in Python - Django: datetime != datetime :-(

FromJaap van Wingerde <mailinglists@vanwingerde.nl>
Date2014-03-03 14:28 +0000
SubjectRe: modification time in Python - Django: datetime != datetime :-(
Message-ID<mailman.7646.1393856904.18130.python-list@python.org>
Op <Tue, 4 Mar 2014 01:08:52 +1100> schreef Chris Angelico <rosuav@gmail.com> in bericht <CAPTjJmrp9Ca5zyfo75NKcX_ik0Qi4kOcjhhY6EEWKQ-xJx7KQg@mail.gmail.com>:

> See if ls is actually giving you ctime rather than mtime - compare the
> results if you ask for os.path.getctime.

jaap@liakoster:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, time
>>> from time import gmtime
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
'2014-03-02T19:03:55Z'
>>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html')))
'2014-03-02T19:03:55Z'
>>> quit()
jaap@liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html
-rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html
jaap@liakoster:~$ 

ls is giving me the modified time.

[toc] | [next] | [standalone]


#67577

Fromdonarb <donarb@nwlink.com>
Date2014-03-03 12:22 -0800
Message-ID<04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com>
In reply to#67554
On Monday, March 3, 2014 6:28:21 AM UTC-8, Jaap van Wingerde wrote:
> Op <Tue, 4 Mar 2014 01:08:52 +1100> schreef Chris Angelico <rosuav@gmail.com> in bericht <CAPTjJmrp9Ca5zyfo75NKcX_ik0Qi4kOcjhhY6EEWKQ-xJx7KQg@mail.gmail.com>:
> 
> > See if ls is actually giving you ctime rather than mtime - compare the
> > results if you ask for os.path.getctime.
> 
> jaap@liakoster:~$ python
> Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import os, time
> >>> from time import gmtime
> >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getmtime('/var/django/test2/art/templates/art_index.html')))
> '2014-03-02T19:03:55Z'
> >>> time.strftime('%Y-%m-%dT%H:%m:%SZ',gmtime(os.path.getctime('/var/django/test2/art/templates/art_index.html')))
> '2014-03-02T19:03:55Z'
> >>> quit()
> jaap@liakoster:~$ ls --full-time /var/django/test2/art/templates/art_index.html
> -rwxrwx--- 1 lia www-data 2456 2014-03-02 19:16:55.568139590 +0000 /var/django/test2/art/templates/art_index.html
> jaap@liakoster:~$ 
> 
> ls is giving me the modified time.

You're using the months format '%m' when you should be using minutes '%M'.

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


#67580

FromChris Angelico <rosuav@gmail.com>
Date2014-03-04 08:11 +1100
Message-ID<mailman.7658.1393881109.18130.python-list@python.org>
In reply to#67577
On Tue, Mar 4, 2014 at 7:22 AM, donarb <donarb@nwlink.com> wrote:
> You're using the months format '%m' when you should be using minutes '%M'.

Heh! I didn't even notice that. When I tested it, I didn't use
strftime at all, just looked at gmtime's output.

ChrisA

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


#67657

FromJaap van Wingerde <mailinglists@vanwingerde.nl>
Date2014-03-04 10:33 +0000
Message-ID<mailman.7699.1393929204.18130.python-list@python.org>
In reply to#67577
Op 2014-03-03T12:22:48 UTC schreef donarb <donarb@nwlink.com> in het
bericht <Re: modification time in Python - Django: datetime !=
datetime :-(>, ID: <04659633-e14e-4d5b-90f2-93af04f056be@googlegroups.com> het volgende. 

> You're using the months format '%m' when you should be using minutes
> '%M'.

Arrgh: stupid error (snik).

p 2014-03-04T08:11:46 UTC schreef Chris Angelico <rosuav@gmail.com> in
het bericht <Re: modification time in Python - Django: datetime !=
datetime :-(>, ID: <CAPTjJmrz-oq-YLZ_0=jHgj9B1y4s_6bZfN52XMn6Xw10TXE2FQ@mail.gmail.com>
het volgende. 

> Heh! I didn't even notice that. When I tested it, I didn't use
> strftime at all, just looked at gmtime's output.

Op 2014-03-04T08:06:21 UTC schreef Ben Finney <ben+python@benfinney.id.au> in het bericht <Re: modification time in
Python - Django: datetime != datetime :-(>, ID: <85txbfhu0i.fsf@benfinney.id.au> het volgende.

> You're using ‘gmtime’ to display the Python datetime value, but ‘ls’
> will display the time in the local timezone. Do you have a strange
> timezone set?

I only use UTC.

Thanks!!!!

The view.py is now as follows.

...
home_lastmod = strftime('%Y-%m-%dT%H:%M:%SZ',gmtime(os.path.getmtime(os.path.dirname(os.path.realpath(__file__ ))+'/templates/art_index.html')))
...

-- 

Jaap van Wingerde
e-mail: 1234567890@vanwingerde.nl

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


#67704

Fromdonarb <donarb@nwlink.com>
Date2014-03-04 08:45 -0800
Message-ID<d6b15bdd-895c-4efd-bd1c-f682de13b051@googlegroups.com>
In reply to#67657
Note that it's bad form to post the same question to different forums, you also posted this question to django-users. By posting to multiple forums, you run the risk of not having the question answered or followed up in one of the forums. This frustrates other users who may one day have a similar problem and find your orphaned question.

Remember, these forums are not just about you, they are also about those who follow later.

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


#67710

FromRoy Smith <roy@panix.com>
Date2014-03-04 12:43 -0500
Message-ID<roy-8A538A.12434104032014@news.panix.com>
In reply to#67704
In article <d6b15bdd-895c-4efd-bd1c-f682de13b051@googlegroups.com>,
 donarb <donarb@nwlink.com> wrote:

> Note that it's bad form to post the same question to different forums, you 
> also posted this question to django-users. By posting to multiple forums, you 
> run the risk of not having the question answered or followed up in one of the 
> forums. This frustrates other users who may one day have a similar problem 
> and find your orphaned question.

Even worse, you run the risk of having it answered differently in 
different places, and then you need to figure out which is right :-)

[toc] | [prev] | [standalone]


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


csiph-web