Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Conversion between PYTHON time and string

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "PYTHON time and string conversion", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "PYTHON time and string conversion" bar!

1. Convert string to time [in] from datetime import datetime [in] # string [in] time_str = '2019-06-2019: 23 in 57' [in] time_rel = datetime.strptime (time_str,'%Y-%m-%d% Hlav% MHD% S') [in] print (type (time_rel)) [in] print (time_rel) [out] [out] 2019-06-2019: 23:57

Memory method

Strptime: it actually means str parase time. The string is parsed into time.

Note:

The format of the string determines the date format after the strptime.

For example:

[in] time_rel2 = datetime.strptime (time_str,'%Y%m%d%H:%M:%S') [out] ValueError: time data '2019-06-2019: 23 in 57' does not match format'% Y%m%d%H:%M:%S'2, time converted to string # followed by [in] time_str2 = datetime.strftime (time_rel) above '% Y-%m-%d% HGV% MVA% S') [in] print (type (time_str2)) [in] print (time_str2) [out] [out] 2019-06-2019: 23Rd 5 strings but there is no limit to the format of time conversion to strings # obvious Time can be converted into any format of string [in] time_str3 = datetime.strftime (time_rel,'%Y%m%d%H%M%S') [in] print (time_str3) [out] 20190620192357

Memory method

Strftime: it means str from time. The string comes from time. It must be that time is converted into a string.

Thank you for your reading, the above is the content of "PYTHON time and string conversion". After the study of this article, I believe you have a deeper understanding of the problem of PYTHON time and string conversion, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report