Convert Military Time from text file to Standard time Python -
i having problems logic on how convert military time text file standard time , discard wrong values. have got point user asked input file , contents displayed text file entered. please me
python's datetime.time
objects use "military" time. can things this:
>>> t = datetime.time(hour=15, minute=12) >>> u = datetime.time(hour=16, minute=44) >>> t = datetime.datetime.combine(datetime.datetime.today(), t) >>> t datetime.datetime(2011, 5, 11, 15, 12) >>> u = datetime.datetime.combine(datetime.datetime.today(), u) >>> t - u datetime.timedelta(-1, 80880)
with little twiddling, conversions ones describe should pretty simple.
without seeing code, it's hard tell want. assume this:
raw_time = '2244' converted_time = datetime.time(hour=int(raw_time[0:2]), minute=int(raw_time[2:4])) converted_time = datetime.datetime.combine(datetime.datetime.today(), converted_time)
now can work converted_time
, adding , subtracting timedelta
objects. fyi, can create timedelta
so:
td = datetime.timedelta(hours=4)
the full list of possible keyword arguments timedelta
constructor here.
Comments
Post a Comment