Python

Some Python Time, Datetime Common Usage Example

1. Get Current Time. >>> import datetime,time >>> >>> now = time.strftime(“%Y-%m-%d %H:%M:%S”) >>> >>> print(now) 2019-03-29 21:27:20 >>> >>> now = datetime.datetime.now() >>> >>> print(now) 2019-03-29 21:27:20.218849 2. Get The Date Of  Last Month’s Last Day. >>> delta_day = datetime.timedelta(1) >>> >>> this_month_first_day = datetime.date(datetime.date.today().year,datetime.date.today().month,1) >>> >>> this_month_first_day datetime.date(2019, 3, 1) >>> >>> last […]

Some Python Time, Datetime Common Usage Example Read More »

How To Convert Timestamp To Specified Format Date String In Python3

When writing Python code, we often encounter the problem of time format. The first thing is the conversion between timestamp and date time fromat string. The timestamp is the number of seconds from 00:00:00 on January 1, 1970 to the present day. In Python, timestamp can be obtained by the time() method in the time

How To Convert Timestamp To Specified Format Date String In Python3 Read More »

How To Use String Truncation Function strip(), lstrip(), And rstrip() In Python3

There are three functions in Python to remove one string’s head and tail characters and the blank characters, they are strip, lstrip and rstrip. strip : Used to remove both head and tail characters and blank characters (includes \n, \r, \t,’   ‘). lstrip : Used to remove head characters and blank characters (includes \n,

How To Use String Truncation Function strip(), lstrip(), And rstrip() In Python3 Read More »

Can Not Find Django Tutorial Django-polls Templates Error

1. Question. According to the official document tutorial of Django project, i meet below problems in the chapter “Advanced tutorial: How to write reusable apps”. Install django-polls to MySite as directed. pip –user install /Users/john/django-polls/dist/django-polls-0.1.tar.gz Run Django server after install successfully. python manage.py runserver Browse url http://127.0.0.1:8000/polls/ in a web browser and returns an error.

Can Not Find Django Tutorial Django-polls Templates Error Read More »