user15361826
user15361826

Reputation: 321

django time convert from string format to standard

Here the time format is not same in terminal and postman,I do not know why this is so, is there any way to change the time value?

 x = VideoDetails.objects.filter(video__coursemodulevideos__module_id).aggregate(Sum('duration'))
    print('x', x)
    print('x',x['duration__sum'])
 result = { "ho":x['duration__sum'] }

In terminal the output is

x {'duration__sum': datetime.timedelta(seconds=130)}

x 0:02:10

but in postman

"hour": { "duration__sum": "P0DT00H02M10S" } Give me a solution to solve this problem.

Upvotes: 1

Views: 64

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476557

You can pass the str(…) of the timedelta to the result, so:

result = { 'hour': str(x['duration__sum']) }

Upvotes: 1

Related Questions