0

I've tried numerous methods to get this working but I have no luck so far. I'm wondering if it has anything to do with the fact I am in the UK and python is looking at my local time.

for instance I want to convert 2013-04-01 to 1364770800000.

any help will be much appreciated.

local = pytz.timezone("UTC") from_date = datetime.datetime.strptime(root.findall("xml stuff")[0].text, "%Y-%m-%d") local_dt_from = local.localize(from_date, is_dst=None) utc_dt_from = local_dt_from.astimezone(pytz.utc).date()

This is what I have used to change my timezone for my date calcuation

Nazilla
  • 581
  • 1
  • 7
  • 17
  • You'll have to show us which code you were using before we can explain it. Also, have you read the description of aware and naive datetime objects at the top of the [`datetime`](https://docs.python.org/3/library/datetime.html) docs? – abarnert Oct 14 '14 at 23:41
  • Also, midnight 2013-04-01 UTC is 1364774400 seconds after the epoch, not 1364770800. Are you trying to subtract a UTC epoch from a British Summer Time date? If so… why? What's the rule you're trying to apply? – abarnert Oct 14 '14 at 23:45
  • I'm trying to match records in a database that has converted dates into milliseconds (unixTimeInMillis) and so by the looks of it has converted dates as above ---> 2013-04-01 to 1364770800000. This was done using UTC timezone so I'm trying to recreate that in my code e.g: ``` from_date = datetime.datetime.strptime(root.findall("xml stuff")[0].text, "%Y-%m-%d") local_dt_from = local.localize(from_date, is_dst=None) utc_dt_from = local_dt_from.astimezone(pytz.utc).date() ``` and then I want to convert that date into milliseconds since epoch – Nazilla Oct 15 '14 at 00:23
  • I don't understand what you mean by "done using UTC timezone". It was done by taking local times, then subtracting the UTC epoch instead of the local epoch, and that's what you need to reproduce? Also, please don't try to put code into comments. First, formatting doesn't work in comments and you get an unreadable mess. Second, the question should have enough information to answer it in the question itself; people who search for questions they can answer or help with, or for questions similar to their problem, don't see the comments. – abarnert Oct 15 '14 at 00:31
  • May be a duplicate of http://stackoverflow.com/questions/6999726/python-converting-datetime-to-millis-since-epoch-unix-time – rmunn Oct 15 '14 at 01:46

0 Answers0