Time Date Conversion?

MRAB python at mrabarnett.plus.com
Wed Nov 4 20:01:28 EST 2020


On 2020-11-04 23:02, Steve wrote:
> The text File entry is:
>     BPd 2020-11-04 17:28:03.352027  66
> 
> I bring it into the program using:
> with open("_TIME-DATE.txt" , 'r') as infile:
>       for lineEQN in infile: # loop to find each line in the file for that
> dose
> and set it in a variable as follows:
> ItemDateTime = lineEQN[7:36].strip()
> 
> When I print ItemDateTime, it looks like:
>        2020-11-04 17:28:03.352027
> 
> How do I display it as "Wednesday, November 4, 2020 5:28pm" ?
> 
Use the datetime module. Parse it with datetime.strptime and then format 
it with the .strftime method of the resultant datetime object.


More information about the Python-list mailing list