473,403 Members | 2,323 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,403 software developers and data experts.

formated local time

I have been trying to find appropriate way to do get local time in
"yyyy-mm-dd hh:mm:ss" format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.l ocaltime()))
It seems to me I'm missing a much simpler method, am I?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
Nov 15 '07 #1
2 1512
On Nov 15, 7:19 am, Nikola Skoric <nick-n...@net4u.hrwrote:
I have been trying to find appropriate way to do get local time in
"yyyy-mm-dd hh:mm:ss" format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.l ocaltime()))
It seems to me I'm missing a much simpler method, am I?

If you want the formatted string, you can use strftime:
>>time.strftime("%Y-%m-%d %H:%M:%S")
'2007-11-15 07:51:12'

--
Hope this helps,
Steven
Nov 15 '07 #2
You could use:

import time
time.strftime( "%Y-%m-%d %H:%M:%S" )
or
time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime() )

Output:
'2007-11-15 11:02:34'

Both strftime calls are equivalent, in this case.
-----Original Message-----
From: py*****************************************@python .org
[mailto:py***************************************** @python.org
] On Behalf Of Nikola Skoric
Sent: Thursday, November 15, 2007 8:20 AM
To: py*********@python.org
Subject: formated local time

I have been trying to find appropriate way to do get local time in
"yyyy-mm-dd hh:mm:ss" format, but the best I got is this:
datetime.datetime.fromtimestamp(time.mktime(time.l ocaltime()))
It seems to me I'm missing a much simpler method, am I?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
--
http://mail.python.org/mailman/listinfo/python-list
Nov 15 '07 #3

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

Similar topics

3
by: Don Grover | last post by:
Hi I have to return dates formated in different ways in an asp page from sql server. What function can I use or how can I return dates formated like so I tried DATEPART ie.. but that does not...
3
by: Randall Parker | last post by:
Suppose one has a database of UTC times that are from different dates in the past. The problem with translating those times to a local time is that one does not know for each UTC time whether the...
3
by: sb Luis | last post by:
I Use the following code to read from MS Word, but I couldent read Formated Text (RTF). How Can I read formated text from MS Word Doc without using clipboard. thanks. Word.ApplicationClass...
2
by: Pat Brown | last post by:
I am pulling an integer value of the amount of seconds since 12:00 am from a SQL Server DB. I want to convert this integer into a formated string or datetime to display a legible time of day. Are...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
13
by: so many sites so little time | last post by:
say i want spacing in my text so instead of doing <br> <br> in between the lines or having to do <href = or <a href = for a link what could i do to have php enter to mysql or retrive it formated?
3
by: lialie | last post by:
Hi, Is there a fine way to read a formated file like: %HEADER title = "Untilted" username = "User" %DATA ....... ....... The formated file may be very popularly, but the module ConfigPaser
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
0
by: pjnambiar | last post by:
Hello friends anyone have idea of converting a formated PDF file into msaccess or excel file. Formated in the sense the informations within pdf file are tabled with different colums. P.J.NAMBIAR
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.