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 »