1

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()
2
  • Please consolidate your sample code. The plotting is unrelated to your question. Commented Aug 15, 2014 at 15:23
  • hi Kay, I have reduce my code, thanks for the reminder Commented Aug 15, 2014 at 15:29

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

5 Comments

@backtotheroots3 why don't you give it a go and see where you get to?
ok I will, sorry because I do not have my program with me right now
Hi john, I already use strftime for sometime else as you have said, so will it cause problems if I use it again?
I tried inserting this ax1.set_title('from {} to {} \n'.format(startTime, endTime, datetime.strptime('%d/%m/%Y %H:%M') but I get a error - strptime() takes exactly 2 arguments
Read my answer again carefully, then read the strftime docs carefully. It's all right here, but you're not using it correctly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.