Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Cristoforo's scratchpad

by Cristoforo (Deacon)
on Jul 26, 2007 at 20:03 UTC ( #628990=scratchpad: print w/ replies, xml ) Need Help??

To demonstrate rounding times to a certain interval in minutes.
#!/usr/bin/perl use strict; use warnings; my $time = time; for my $interval (1,5,10,15,20,30) { print "### INTERVAL = $interval minute(s)\n"; for (1..3) { my $t = int rand $time; print ' ', scalar localtime($t), "\n"; $t -= $t % ($interval * 60); print ' ', scalar localtime($t), "\n\n"; } } __END__ ### INTERVAL = 1 minute(s) Fri Aug 1 04:25:25 2008 Fri Aug 1 04:25:00 2008 Tue Nov 4 02:53:35 1980 Tue Nov 4 02:53:00 1980 Fri Feb 12 02:53:36 1999 Fri Feb 12 02:53:00 1999 ### INTERVAL = 5 minute(s) Fri Feb 11 11:42:57 2000 Fri Feb 11 11:40:00 2000 Sat Oct 30 10:44:39 1993 Sat Oct 30 10:40:00 1993 Thu Aug 11 20:54:51 1977 Thu Aug 11 20:50:00 1977 ### INTERVAL = 10 minute(s) Sun Jun 2 21:28:54 1974 Sun Jun 2 21:20:00 1974 Fri Jun 29 13:10:17 2007 Fri Jun 29 13:10:00 2007 Wed Dec 17 22:21:13 1980 Wed Dec 17 22:20:00 1980 ### INTERVAL = 15 minute(s) Thu Mar 24 18:19:18 1977 Thu Mar 24 18:15:00 1977 Sun May 17 21:43:08 1970 Sun May 17 21:30:00 1970 Sun Jul 22 13:02:46 1973 Sun Jul 22 13:00:00 1973 ### INTERVAL = 20 minute(s) Thu Oct 27 15:34:23 1977 Thu Oct 27 15:20:00 1977 Wed Mar 19 16:44:12 1980 Wed Mar 19 16:40:00 1980 Tue Sep 7 22:05:36 1971 Tue Sep 7 22:00:00 1971 ### INTERVAL = 30 minute(s) Wed Nov 17 05:03:53 2004 Wed Nov 17 05:00:00 2004 Fri Jan 11 03:18:30 2008 Fri Jan 11 03:00:00 2008 Sun Oct 9 20:41:01 1994 Sun Oct 9 20:30:00 1994
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-07-13 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (250 votes), past polls