Python change time -2 hours
#1
Hi .. I'm making a simple Kodi add-on for myself. I'm a complete layman and I got trapped where I don't know how to help or help the internet.

I am importing the date and time from the Guide (EPG) meeting in the form of eg: 1.1.2000 10:00 in the variable "olddate"
since I need to convert the date to a certain form which I managed after several attempts but I still need the resulting time in the variable "newdate" to be two hours less (UTC)

I have now:
Code:
ADRESA/20000101_name_20000101_100000/ADRESA

I need:
Code:
ADRESA/20000101_name_20000101_080000/ADRESA

source:
Code:
import xbmc 
import xbmcgui 
from datetime import datetime, timezone, timedelta 

title = xbmc.getInfoLabel('Listitem.Title') 
olddate = xbmc.getInfoLabel('Listitem.Date') 
start = xbmc.getInfoLabel('Listitem.StartTime') 
name = xbmc.getInfoLabel('ListItem.ChannelName') 
url = 'ADRESA' 
get = '_' 
newdate = datetime.strptime(olddate, "%d.%m.%Y %H:%M") 

file = 'ADRESA' + newdate.strftime("%Y%m%d") + get + name.replace(" ", "_") + get + newdate.strftime("%Y%m%d_%H%M%S") + url 

xbmc.Player().play(file)

very thanks for me help
Reply
#2
You can use timedelta to subtract from a datetime like so
python:

bla = datetime.datetime.strptime('20.04.1084 12:00', "%d.%m.%Y %H:%M")
d = bla - datetime.timedelta(hours=2)
You can also try to play with the formatter and tell it that this should be in a certain timezone
https://docs.python.org/3/library/dateti...e-behavior
Reply
#3
thank you works well. but I came across another problem. see thread HERE

Code:
newdate = datetime.strptime(olddate, "%d.%m.%Y %H:%M") + (timedelta(hours=-2))
Reply

Logout Mark Read Team Forum Stats Members Help
Python change time -2 hours0