0

The last.fm API using user.getRecentTracks method's response supplies a date in the following format:

"date": {
    "#text": "11 Dec 2015, 01:41", 
    "uts": "1449798068"
}, 

What is this "uts" field and how do I convert it into datetime string for a MySql database in python? Would your suggested answer be more efficient than using datetime.datetime.strptime() method to convert the text string given?

Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
Jason Melo Hall
  • 652
  • 2
  • 11
  • 23

1 Answers1

1

uts looks like a timestamp. The abbreviation probably stands for UTC timestamp or Unix Timestamp. I'm not sure which, but, it simple to convert it to a datetime object

>>> from datetime import datetime
>>> dt = datetime.fromtimestamp(1449798068)
>>> print(dt)
datetime.datetime(2015, 12, 10, 20, 41, 8)

It seems the #text key has the time in a local timezone, which is five hours ahead.

Haleemur Ali
  • 26,718
  • 5
  • 61
  • 85
  • @JasonMeloHall: do you see that the time in the answer differs from "#text" value? Note: `datetime.utcfromtimestamp()` returns a correct value here. Read [my comment to the corresponding answer on the duplicate](http://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date-in-python#comment30046351_3682808) – jfs Dec 14 '15 at 13:14
  • Thanks @J.F.Sebastian. That was my mistake. Since the question is duplicate, I wont amend my answer. Jason, please refer to the linked question & maybe consider deleting this thread. – Haleemur Ali Dec 14 '15 at 14:40