Adjust datetime index for daylight saving

时间:2016-10-20 12:49:21

标签: python dst

I have a set of data with a timestamp (EST) that has not been adjusted for daylight saving, is there any way to do this?

Note: I've not been able to find similar questions, I am then converting into UTC but not having issues with that.

Sample data:

DateTime,           Open,  High, Low,   Close 
2002-03-03 16:00:00,115.49,115.6,115.21,115.25
2002-03-03 20:00:00,115.25,115.41,115.05,115.15
2002-03-04 00:00:00,115.15,115.18,114.69,114.78
2002-03-04 04:00:00,114.79,114.85,114.12,114.32
2002-03-04 08:00:00,114.32,115.17,114.27,115.15
2002-03-04 12:00:00,115.13,115.18,114.83,115.01
2002-03-04 16:00:00,115.02,115.17,114.75,115.13
2002-03-04 20:00:00,115.13,115.36,115.03,115.14
2002-03-05 00:00:00,115.14,115.33,114.86,115.0 

2 个答案:

答案 0 :(得分:1)

I would suggest using the pytz module. For instance:

import pytz
from dateutil import parser


def convert_timezone(dt, destination_timezone, source_timezone='UTC'):
    source_timezone = pytz.timezone(source_timezone)
    destination_timezone = pytz.timezone(destination_timezone)
    dt = source_timezone.localize(dt, is_dst=None).astimezone(destination_timezone)
    return dt.replace(tzinfo=None)


date = parser.parse("2002-03-03 16:00:00")
print convert_timezone(date, 'Israel')

output

2002-03-03 18:00:00

答案 1 :(得分:0)

To parse your date time :

from dateutil.parser import parse
date_object = parse("2002-03-03 16:00:00").replace(tzinfo=None)