Python gets file timestamp

Source: Internet
Author: User
Http://zhidao.baidu.com/link?url=wNI9K20mR7-9necxd6zK1bWnBQ-EmuggOzS0JNVZ0G_ Mpsqn31ti6l3i0j0dyycanhuxoqls6axyv0cb0yx3cg9dncoiv5n4qegw7hafqxi

We get through the file attributes, the Os.stat () method:

>>> Import OS
>>> Statinfo=os.stat (r "C:/1.txt")
>>> Statinfo
(33206, 0L, 0, 0, 0, 0, 29L, 1201865413, 1201867904, 1201865413)
Use the return value of Os.stat statinfo three properties to get the file creation time, etc.
St_atime (Access Time), St_mtime (modified time), St_ctime (creation time), for example, get file modification time:
>>> Statinfo.st_mtime
1201865413.8952832
This time is a Linux timestamp and needs to be converted
Use the LocalTime function in the time module to know:
>>> Import Time
>>> Time.localtime (Statinfo.st_ctime)
(2008, 2, 1, 19, 30, 13, 4, 32, 0)
February 1, 2008 19:30 13 seconds (2008-2-1 19:30:13)



Python gets file timestamp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.