473,473 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

time.localtime() Format Question


Hello Everyone,

I am a brand new Python programmer with barely a month of
experience under my belt.
Here are my specs:

Mac OSX Panther 10.3.9
Jython 2.1 implementation with Hermes BBS python module installed
And now the problem...

Right now I am having a small problem figuring out how to
properly format the "User Last Log-On" date for the new
external/door that I am writing for our Hermes BBS.

Initially, I was using the following in my user
initialization function near the top of the code:

user.data.usrUndrLast = time.localtime()

"user.data.usrUndrLast" is a user data object that I created
to display the last time that a person used the external. As
you can see, I an setting the value of the object to
"time.localtime()".

The problem is that the above code gave me a long string like
this:

(2006, 8, 19, 23, 39, 15, 5, 231, 0)

Well, that obviously was not what I wanted or needed. I don't
need seconds, or whatever that is that follows after
seconds...And that isn't the format I wanted either.

So I scrounged around in the example code for another
external I have here, as well as in the hermes.py, (module
which contains some of the BBS's proprietary functions), the
jython-2.1 folder, (Python implementation I am using with the
BBS), and even in my OSX Python installation, and then also
on the web, looking for a clue regarding how to get it to do
what I want it to do.

I figured out that adding [:3] like this:

user.data.usrUndrLast = time.localtime()[:3]

....would reduce it to just "(2006, 8, 19)", but that is still
not what I want it to do. The format is wrong.

I found a lot of interesting stuff inside of "rfc822.py"
concerning date and time formats, but I am still not grasping
quite how to do this.

Right now, I am getting a TypeError, I guess because
time.localtime only deals with integers, and I am trying to
throw strings at it as well, like this:

user.data.usrUndrLast = time.localtime('%a, %d %b %Y')

I was hoping that the above code would produce something like this:

Sun 20 Aug 2006

....but what I am getting is a TypeError which states:

"TypeError: localtime(): 1st arg can't be coerced to double"

So at this point, I am pretty stumped. In the list of
players, I just want it to show when they were last logged
into the external, preferably in one of the following
formats:

Sun 20 Aug 2006
Sun Aug 20 2006
Aug 20 2006
08-20-06
08-20-2006
08/20/2006
08/20/06

Once the above code, (user.data.usrUndrLast = time.localtime),
initializes their last log-on date, I am using the results in
a user list by appending the data to the user list like this:

for u in external.users.values():
usrList.append({
'name': u.data.usrUndrName,
'levl': u.data.usrUndrLevl,
'scor': u.data.usrUndrScor,
'last': u.data.usrUndrLast, # The one we're dealing with
})

The above list code queries the external for the values that
it has stored for each user. When it gets to the "last" item
in the list, the external is supposed to send it the value
for "u.data.usrUndrLast", (which it does), which is filled in
with the value of "time.localtime()" Once the list is made,
the "last" code will be displayed in the user list using this
piece of code:

print Style(fgLtGreen)('%(last)-10s' % markUsr)

For the record, I do have "import time" at the top of my
code. I looked all over the place for a module called
"time.py", but couldn't find one. So I didn't quite
understand where "time.py" was being imported from. I finally
figured that it must just be a function which is being
imported from one of the jython modules that I was looking
at...although I never found an exact function called "time()"
or "time.localtime().

So if anyone can lend me a hand with this, I'd really appreciate
it. I am really working hard, and doing the best I can to learn
Python, (my very first programming language), but I still require
some guidance.

If anyone here can tell me how to get the results that I want, I
would really appreciate if you would write to me directly at:

we*******@endtimeprophecy.net

Thanks so much.
Aug 20 '06 #1
1 4350
OleMacGeezer wrote:
Hello Everyone,
Hola
(2006, 8, 19, 23, 39, 15, 5, 231, 0)

Well, that obviously was not what I wanted or needed. I don't
need seconds, or whatever that is that follows after
seconds...And that isn't the format I wanted either.
I'm sorry I didn't have time to grep your entire post, but maybe this
will help:
>>import time
t = time.localtime()
t
(2006, 8, 20, 12, 48, 52, 6, 232, 1)
>>time.strftime('%a, %d %b %Y', t)
'Sun, 20 Aug 2006'

-greg
Aug 20 '06 #2

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

Similar topics

3
by: beliavsky | last post by:
Using Python 2.4 on Windows, for me the command print os.stat("temp.txt") gives 1115478343 , which is "seconds since the epoch". How can I get the modification time in a format such as
14
by: George | last post by:
In Time.h there is a structure defined for time settings. I'm building an embedded system that has a Real Time Clock but it's not PC compatible. My question is: I don't some elements of the...
3
by: Ilja Booij | last post by:
Hi all, I have some trouble with the following: I'm getting a time string, in YYYY-MM-DD HH:mm:ss format, which I need to translate into a string with DD-Mon-YYYY HH:mm:ss +HHMM, where the...
17
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
5
by: Summu82 | last post by:
HI I have to convert a time in the format i have year month day hour min and seconds I need to convert this into time in seconds since 1 jan 1970 i.e the
18
by: moni | last post by:
I have 2 time values: System time and an input from the user. 1) System time is in the form of seconds from 1/1/1970 calculated by using
9
by: Frank | last post by:
I have a time saved in a time_t variable. I'd like to be able to display the number of days since then but can't find anything built-in that will help. Failing that I'd like to display the...
3
by: bwooster47 | last post by:
Following python code prints out incorrect UTC Offset - the python docs say that %z is not fully supported on all platforms - but on Linux Fedora FC5, perl code works and python does not - is this...
5
by: HMS Surprise | last post by:
I wish to generate a datetime string that has the following format. '05/02/2007 12:46'. The leading zeros are required. I found '14.2 time' in the library reference and have pulled in localtime....
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.