user5349891
user5349891

Reputation:

Python specify file creation time by milliseconds

After some research I couldn't find any solution to this so here it goes:

Python's command:

time.ctime(os.path.getctime('/path'))

displays output as (e.g):

Fri Dec 2 16:06:05 2016.

How can I make it display not only hours/minutes/seconds but also milliseconds?

Upvotes: 1

Views: 3386

Answers (2)

Arduino_Sentinel
Arduino_Sentinel

Reputation: 819

Use os.stat("/").st_ctime_ns gain nanoseconds level

import os
import datetime

datetime.datetime.fromtimestamp(os.stat("/").st_ctime_ns)

Upvotes: 1

User2342342351
User2342342351

Reputation: 2174

You can use stat:

import datetime
import os

datetime.datetime.fromtimestamp(os.stat('/').st_ctime)

Note that if you modified the metadata of the file, you will get this as the "ctime", getting the creation date after modification of metadata is not possible on UNIX platforms.

Upvotes: 0

Related Questions