backtotheroots3
backtotheroots3

Reputation: 11

Changing Datetime Format in Python

how do I change format to DD/M/YYY H:M for this line:

ax1.set_title('from {} to {} \n'.format(startTime, endTime, fontsize=22))

cause currently when I run the module it is displayed this way: YYYY-MM-DD H:M:S

This is my code:

linematchregex = re.compile('(\d+/\d+/\d+ \d+:\d+),(\d+\.\d+)')

startTime = datetime.strptime(raw_input('please enter start time :'), '%d/%m/%Y %H:%M'
endTime   = datetime.strptime(raw_input('please enter end time :') , '%d/%m/%Y %H:%M')


**ax1.set_title('from {} to {} \n'.format(startTime, endTime, fontsize=22))**
ax1.set_ylabel('Temp')
ax1.set_xlabel('Time')
plt.show()

Upvotes: 1

Views: 143

Answers (1)

John Zwinck
John Zwinck

Reputation: 249103

You need to use strftime() (sort of the inverse of strptime() which you already use): https://docs.python.org/2/library/time.html#time.strftime

Upvotes: 3

Related Questions