Hướng dẫn time to string python
The Show Example 1: datetime to string using strftime()The program below converts a
When you run the program, the output will something like be: year: 2018 month: 12 day: 24 time: 04:59:31 date and time: 12/24/2018, 04:59:31 Here, year, day, time and date_time are strings, whereas now is a How strftime() works?In the above program,
Example 2: Creating string from a timestamp
When you run the program, the output will be: Date time object: 2018-06-12 09:55:22 Output 2: 06/12/2018, 09:55:22 Output 3: 12 Jun, 2018 Output 4: 12 June, 2018 Output 5: 09AM Format Code ListThe table below shows all the codes that you can pass to the
Example 3: Locale's appropriate date and time
When you run the program, the output will be: Output 1: Tue Jun 12 09:55:22 2018 Output 2: 06/12/18 Output 3: 09:55:22 Format codes We also recommend you to check Python strptime(). The |