Need only time

hi all,
how to get time alone from this format
(1986, 1, 28, 17, 39, 18)

Shanmu G. wrote:

hi all,
how to get time alone from this format
(1986, 1, 28, 17, 39, 18)

Use Time.mktime

Regards
Stefan

On Wed, 10 Dec 2008 10:54:29 +0100, Shanmu G.
[email protected] wrote:

how to get time alone from this format
(1986, 1, 28, 17, 39, 18)

Given the numbers I suppose that the format is as follows:

datetime = [1986, 1, 28, 17, 39, 18] # [Y, m, d, H, M, S]; array of 

integers

where Y is the year, m is the month, d the day, H the hour, M the minute
and S the second (at least this is the order of arguments provided to
Time.utc and similar functions). I am not sure what you mean by “get
time”. For a string representation of the time you could use:

Time.utc(*datetime).strftime("%H:%M:%S")

which in the given example returns

"17:39:18"

The same could also be done without using any Time functions using

"%02d:%02d:%0d" % datetime[-3..-1]

where %02d results in a zero-padded (hence the 0) two character (hence
the 2) representation of the values. While in this case it is not
needed, it makes sure that that (0, 8, 15, 1, 2, 3) results in
“01:02:03” and not in “1:2:3”.

In the case you start with

datetime = Time.utc(1986, 1, 28, 17, 39, 18)

and want a numerical array of hour, minute and second you can use

[datetime.hour, datetime.min, datetime.sec]

I hope I understood your question correctly.

Josef ‘Jupp’ Schugt