1

When using get_key and then fetching last_modified property, there is deviation of 3 hours.

k = b.get_key('av-bait/modules/reporters.py')
print k.last_modified    

I get: 'Sat, 17 May 2014 18:42:02 GMT', while the file was updated at 21:42:02 as the following picture indicates:

File as shown in se console

Any idea how to fetch the gmt via s3?

Thanks

Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
omer bach
  • 2,345
  • 5
  • 30
  • 46

3 Answers3

1

Take a look at the timezone of your screenshot. The screenshot states the file was modified at 21:42:02 GMT+300 which equals 18:42:02 GMT so it's in fact the same timestamp and you only need to do some timezone magic to convert it.

Knut
  • 1,792
  • 13
  • 9
  • how do I retrieve the GMT +300 via s3 api? – omer bach May 17 '14 at 19:24
  • You can't. This should be a normal `datetime.datetime` object so I suggest for example to follow [this post](http://stackoverflow.com/questions/4770297/python-convert-utc-datetime-string-to-local-datetime). – Knut May 17 '14 at 19:29
1

The solution is very simple - the timestamp is correct.

Mind the +03:00:00 at the timestamp on web. If you apply it to the time you see before, you will get exactly the timestamp you get by asking last_modified

Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
1

If you want to adjust the string by three hours you can use:

>>> t='Sat, 17 May 2014 18:42:02 GMT'
>>> from datetime import datetime
>>> str_time= datetime.strptime(t,'%a, %d  %B %Y %H:%M:%S GMT')
>>> updated_time= str_time.replace(hour=str_time.hour+3)
>>> print updated_time
2014-05-17 21:42:02

There are many ways to do it, have a look at the datetime docs,

jonatan
  • 9,011
  • 2
  • 30
  • 34
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • FWIW, the correct date format for the default S3 `last_modified` is: `%a, %d %b %Y %H:%M:%S GMT` – 0xack13 Oct 22 '18 at 07:10