Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

api - Convert the day time on python

I have a question based on the conversion of a date and time using the start_time element's Google Calendar API, how could I convert it to a day, month and year of Latin America without more, if you could help me please the datetime: 2021-01-19T09:00:00-05:00 I need the follow example: day/mount/year 15/01/2021 I've been trying and can't find a way to convert properly, please if you could help me.

question from:https://stackoverflow.com/questions/65838481/convert-the-day-time-on-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the datetime library:

import datetime

date_str = "2021-01-19T09:00:00-05:00"
date_obj = datetime.datetime.strptime(date_str[:10], "%Y-%m-%d").strftime("%d/%m/%Y")

print(date_obj)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...