473,385 Members | 1,753 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,385 software developers and data experts.

Time functions


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. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

Thanks,

jvh (whose newbieism is most glaring)

May 2 '07 #1
5 1326
On May 2, 12:00 pm, HMS Surprise <j...@datavoiceint.comwrote:
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. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

Thanks,

jvh (whose newbieism is most glaring)
Oops, it appears I overlooked strftime.

Regrets,

jvh

May 2 '07 #2
In <11*********************@o5g2000hsb.googlegroups.c om>, HMS Surprise
wrote:
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. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.
You mean like `time.strftime()`!? :-)

Ciao,
Marc 'BlackJack' Rintsch
May 2 '07 #3
On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
In <1178125256.640115.26...@o5g2000hsb.googlegroups.c om>, HMS Surprise
wrote:
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. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.

You mean like `time.strftime()`!? :-)

Ciao,
Marc 'BlackJack' Rintsch
Thanks for posting.

I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

thanx,
jvh

May 2 '07 #4
On May 2, 10:21 am, HMS Surprise <j...@datavoiceint.comwrote:
On May 2, 12:03 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
In <1178125256.640115.26...@o5g2000hsb.googlegroups.c om>, HMS Surprise
wrote:
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. Are there any formatting functions available or do I need
to make my own? Perhaps there is something similar to C's printf
formatting.
You mean like `time.strftime()`!? :-)
Ciao,
Marc 'BlackJack' Rintsch

Thanks for posting.

I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

thanx,
jvh
I would think that what you have written there shouldn't work at
all...

it would need to be:

Expand|Select|Wrap|Line Numbers
  1. from time import localtime, strftime
  2.  
to use the prepended module name just do this instead:

Expand|Select|Wrap|Line Numbers
  1. import time
  2. t = time.strftime('%m/%d/%Y %H:%M', time.localtime())
  3.  
May 2 '07 #5
On 2007-05-02, Matimus <mc******@gmail.comwrote:
>I think I have an import misconception.

I use
import from time localtime, strftime
t = strftime('%m/%d/%Y %H:%M', localtime())

This works. How would one use it with the module name pre-pended?

I would think that what you have written there shouldn't work at
all...
It doesn't.
it would need to be:

Expand|Select|Wrap|Line Numbers
  1. from time import localtime, strftime
  2.  

to use the prepended module name just do this instead:

Expand|Select|Wrap|Line Numbers
  1. import time
  2. t = time.strftime('%m/%d/%Y %H:%M', time.localtime())
  3.  
or just this

t = time.strftime('%m/%d/%Y %H:%M')

time.strftime() has used the localtime() value by default for
a while now.
--
Grant Edwards grante Yow! There's enough money
at here to buy 5000 cans of
visi.com Noodle-Roni!
May 2 '07 #6

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

Similar topics

6
by: Rick | last post by:
Hello all. I have an index.php file that has a lot of functions that I wrote. Let's say for the sake of argument that there are 1000 functions of 100 lines each. The index.php file is invoked...
18
by: bart_nessux | last post by:
I need a script to call several functions at the same time. How does one call more than one function simultaneously?
11
by: Bryant Huang | last post by:
Hello! I would like to read in files, during run-time, which contain plain Python function definitions, and then call those functions by their string name. In other words, I'd like to read in...
3
by: Luis Pedro | last post by:
Hi there, Can anyone tell me if there is any time and date standard functions for C++ and, if so, were can I find documentation about it? If such functions do not exist, any hint of what library...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
5
by: RICHARD BROMBERG | last post by:
I am writing an ASP program that includes a Form. When the Form is submitted I use the Date() and Time() functions to put the date and time into the Body part of the e-mail. The time reported is...
5
by: rs | last post by:
I have a table with a timestamp field which contains the date and time. ie. 9/13/2004 9:10:00 AM. I would like to split this field into 2 fields, one with just the DATE portion ie 9/13/2004 and...
7
by: dc | last post by:
Can anybody think of a situation where virtual function's address resolution/ something related to virtual is done at compile time
0
hqprog
by: hqprog | last post by:
Having search extensively I've learned the two functions timegm and gmtime_r though in the GNU standard C library extend the ISO standard. I need to use these two functions in myprog.c (on pc - ...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...

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.