473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

get file modification time in mm/dd/yyyy format?

Using Python 2.4 on Windows, for me the command

print os.stat("temp.txt")[stat.ST_MTIME]

gives

1115478343 ,

which is "seconds since the epoch". How can I get the modification time
in a format such as

05/07/2005 11:05 AM

as in Windows with the dir command? Ideal would be a tuple of 6 values,
(year,month,day,hour,minute,second). Thanks.

Jul 19 '05 #1
3 6032
be*******@aol.com wrote:
Using Python 2.4 on Windows, for me the command

print os.stat("temp.txt")[stat.ST_MTIME]

gives

1115478343 ,

which is "seconds since the epoch". How can I get the modification time
in a format such as

05/07/2005 11:05 AM

as in Windows with the dir command? Ideal would be a tuple of 6 values,
(year,month,day,hour,minute,second). Thanks.


Do you want the time formatted as above, or as a tuple, since you seem
unclear?

time.strftime('%m/%d/%Y %H:%M %p', time.localtime(time.time()))

time.localtime(time.time())[:6] would do the latter...

Check the "time" module docs for more.

-Peter
Jul 19 '05 #2
Tried this it on linux, should work under windows as well I think
martin@ubuntu:~$ python
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
py> import time
py> t = time.localtime(1115478343)
py> print t
(2005, 5, 7, 17, 5, 43, 5, 127, 1)
py> print time.asctime(t)
Sat May 7 17:05:43 2005
py>

Jul 19 '05 #3
Le 7 May 2005 08:23:48 -0700, be*******@aol.com a écrit :
Using Python 2.4 on Windows, for me the command

print os.stat("temp.txt")[stat.ST_MTIME]

gives

1115478343 ,

which is "seconds since the epoch". How can I get the modification time
in a format such as

05/07/2005 11:05 AM

as in Windows with the dir command? Ideal would be a tuple of 6 values,
(year,month,day,hour,minute,second). Thanks.

I type
import time
dir(time)
lot of stuff
help(time.localtime)
localtime([seconds]) ->
(tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wd ay,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local time.
When 'seconds' is not passed in, convert the current time instead.
time.localtime(1115478343)

(2005, 5, 7, 17, 5, 43, 5, 127, 1)
it seems to be 7 may 2005 17h 5 minutes 43 seconds

To have such a formatting you have to type help(time.strptime) which
sadly will say
See the library reference manual for formatting codes (same as strftime()).

---
there is no perfect world

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
1
by: Ricky Cruz | last post by:
Hi, On SQLServer 2000, I have a table with a following structure: MYTABLE col1 char, col2 date, col3 number My Objective:
1
by: Scott Berry | last post by:
Hi, I have an ADP file that stores dates in a datetime field type and I want to query the table for all records for a single date (ie. ignore the time). I want it to automatically return all...
3
by: Ivan V via DotNetMonster.com | last post by:
Dear All: I got a serious problem in updating the date field from vb.net to abd dbf file. My code is as follow: Dim ConnectionString As String Dim cake As Date = Date.Parse(idate) ...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
4
by: Jason | last post by:
I need to open a file for reading, but I only know part of it's name. The file I want to read is in the format of xxx-yyyy-zzz.EXT The last three digits of the file name are different on each...
0
by: whitemoss | last post by:
Hi All, I had written a code to read a file and insert it's contents to the database. Since I will receive 3 files every hour, so, this program should read those files and insert the contents...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
3
by: DontB3 | last post by:
Hi, I'm new in this forum, and i hope someone can help. I'm creating an automatic application that transfer a database from Access -> DBF -> Oracle. When My App try to execute Insert SQL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.