Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to convert datetime to string in Python

3 Answers

0 votes
import datetime

today = datetime.datetime.now()

print(str(today))



'''
run:

2017-09-28 12:32:23.553181

'''

 



answered Sep 28, 2017 by avibootz
edited May 11, 2024 by avibootz
0 votes
import datetime

today = datetime.datetime.now()

print(repr(today))



'''
run:

datetime.datetime(2017, 9, 28, 12, 38, 0, 57398)

'''

 



answered Sep 28, 2017 by avibootz
edited May 11, 2024 by avibootz
0 votes
from datetime import datetime
   
d = datetime.now()
  
s = d.strftime("%B the %d of %Y is %A at %I:%M %p")
  
print(s)
print(type(s).__name__)
   
   
   
   
'''
run:
   
June the 21 of 2021 is Monday at 03:45 PM
str
   
'''

 



answered May 11, 2024 by avibootz

Related questions

2 answers 156 views
1 answer 131 views
3 answers 222 views
3 answers 206 views
3 answers 175 views
2 answers 162 views
...