0

I have the following string in python:

message = "2015-08-26T19:30:00+0200"

And I want to retrieve the time from it so I used:

import pandas as pd
import datetime
date=pd.to_datetime(message)
m=datetime.time(date)

The output is

17:30:00

How can I get 19:30 regardless of the DST

Roland
  • 73
  • 8
  • 3
    Shouldn't DST only adjust the time by 1 hour? Aren't you really asking about the time zone (which, if you notice, is `+0200`? – Scott Hunter Aug 26 '15 at 18:45
  • `pandas.to_datetime` returns an object storing the date in UTC, and as far as I know, doesn't retain any information about which timezone the string was in. – chepner Aug 26 '15 at 19:12
  • Indeed I meant the Time zone (and the DST included in this time zone), I thought that too.. but the output is using the timezone and I cant find a way to ignore it – Roland Aug 27 '15 at 07:26
  • your question is "how to get the local time (+0200 utc offset) instead of utc time." – jfs Sep 04 '15 at 12:38
  • related: [How to parse dates with -0400 timezone string in python?](http://stackoverflow.com/q/1101508/4279) – jfs Sep 04 '15 at 12:39

2 Answers2

1

I used the strptime with the %z format and it worked

import datetime
message = "2015-08-26T19:30:00+0200"
fmt = '%Y-%m-%dT%H:%M:%S%z'
d=datetime.datetime.strptime(message, fmt)
print(d.time())
Roland
  • 73
  • 8
0

Using arrow:

import arrow
message = "2015-08-26T19:30:00+0200"
m = arrow.get(message, 'YYYY-MM-DDTHH:mm:ssZ')
print m.format('YYYY-MM-DDTHH:mm:ssZ') # 2015-08-26T19:30:00+0200
print m.format('HH:mm:ss') # 19:30:00

Information about arrow is at http://crsmithdev.com/arrow/.