Behave Differently According to Time (Hour)

F

Fengshui

Is there an easy way to know what hour I am in from the output of time()?

1 line calculation to know if it is day time or night time (7pm-6am ETS)

I think there must be way just like this
(time + factor) %something here = bahbahbah.. then from bahbahbah, I can
tell what hour is now.

Thanks.
 
A

A. Sinan Unur

Is there an easy way to know what hour I am in from the output of time()?

1 line calculation to know if it is day time or night time (7pm-6am ETS)

I think there must be way just like this
(time + factor) %something here = bahbahbah.. then from bahbahbah, I can
tell what hour is now.

perldoc -f time
perldoc -f localtime
perldoc -q gmtime

What part is not clear?
 
J

John W. Krahn

Fengshui said:
Is there an easy way to know what hour I am in from the output of time()?

1 line calculation to know if it is day time or night time (7pm-6am ETS)

Maybe, but it would be easier to use the output from localtime().

perldoc -f localtime



John
 
T

Tony Curtis

Is there an easy way to know what hour I am in from the
output of time()? 1 line calculation to know if it is day
time or night time (7pm-6am ETS)

perldoc -f localtime

hth
t
 
J

Jürgen Exner

Fengshui said:
Is there an easy way to know what hour I am in from the output of
time()?

Certainly, if you insist on doing it the hard way.
time() returns the seconds since 00:00:00 UTC, January 1, 1970 (at least on
Unix systems).
Just divide them by 3600 and you get the hours since the epoch. Divide those
hours modulo 24 and you get the hour in the day in UTC. Adjust for the local
time zone and your are done.

However, why aren't you simply using localtime()?

jue
 
J

James Willmore

Is there an easy way to know what hour I am in from the output of
time()?

1 line calculation to know if it is day time or night time (7pm-6am
ETS)

I think there must be way just like this
(time + factor) %something here = bahbahbah.. then from bahbahbah, I
can tell what hour is now.

You could look over the Date::Calc or Date::Manip modules as well as
the other posts made.

With the 2 modules I mentioned, you can not only find out what time it
is now, but perform time calculations as well.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Johnson's First Law: When any mechanical contrivance fails, it
will do so at the most inconvenient possible time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top