format a unixtimestamp according to kodi local settings?
#1
hi there - can someone point me the right way for this:

I need to format a unix-timestamp (seconds since 1970...) to a proper localized/region string with python in a script context.
Localized according to the settings of kodi for region/language.
kodi3: LE 7.93.5 on Pi3
kodi4: LE 7.93.5 on Wetek Play 2
Server vdr 2.2.0, vnsi,...
Reply
#2
get the kodi time & date settings:
http://mirrors.xbmc.org/docs/python-docs...-getRegion


python time conversion:
https://docs.python.org/2/library/time.html


this is what i'm using in my addons:
Code:
import time, xbmc

DATEFORMAT = xbmc.getRegion('dateshort')
TIMEFORMAT = xbmc.getRegion('meridiem')

def convert_date(stamp):
    date_time = time.localtime(stamp)
    if DATEFORMAT[1] == 'd':
        localdate = time.strftime('%d-%m-%Y', date_time)
    elif DATEFORMAT[1] == 'm':
        localdate = time.strftime('%m-%d-%Y', date_time)
    else:
        localdate = time.strftime('%Y-%m-%d', date_time)
    if TIMEFORMAT != '/':
        localtime = time.strftime('%I:%M%p', date_time)
    else:
        localtime = time.strftime('%H:%M', date_time)
    return localtime + '  ' + localdate
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Thanks a lot - will work for me
kodi3: LE 7.93.5 on Pi3
kodi4: LE 7.93.5 on Wetek Play 2
Server vdr 2.2.0, vnsi,...
Reply
#4
This can be done quite a bit more efficient and correct, since xbmc.getRegion() returns the strfmt you need.

python:

import time
import xbmc

DATEFORMAT = xbmc.getRegion('dateshort')
TIMEFORMAT = xbmc.getRegion('meridiem')

def convert_date(stamp):
    return time.strftime(DATEFORMAT + ' ' + TIMEFORMAT, time.localtime(stamp))
Reply

Logout Mark Read Team Forum Stats Members Help
format a unixtimestamp according to kodi local settings?0