# What Is Time ?

In [40]:
from IPython.display import HTML
HTML('<iframe src=http://randomibis.com/coolclock/justclock.html width=340 height=340></iframe>')

Out[40]:
In [43]:
HTML('<iframe src=http://www.uize.com/examples/digital-clock.html width=850 height=600></iframe>')

Out[43]:

#### Time always ticks and never stops¶

In computer world, time starts at 12:00am, January 1, 1970 (epoch). Every time interval is a tick or second.

In python world, there are 3 basic modules to track time:

Question: how many ticks are there since epoch?

In [18]:
import time
nticks = time.time()
print "It is now %f ticks (seconds) past epoch" % nticks

It is now 1353713584.312000 ticks (seconds) past epoch


#### Time is structured as a tuple of 9 pieces¶

IndexAttributeMeaningValueRange
0tm_year4-digit year20121 - 9999
1tm_monmontd111 - 12
2tm_mdayday of montd231 - 31
3tm_hour24 hour180 - 23
4tm_minminute520 - 59
5tm_secsecond60 - 61 (60 or 61 are leap seconds)
6tm_wdayday of week40 - 6 (0 for Monday)
7tm_ydayday of year3281 - 366 (Julian day)
8tm_isdstdaylight savings0-1, 0, 1 (-1 means library determines DST)
In [6]:
print "Year (Min, Max): (%d, %d)" % (datetime.MINYEAR, datetime.MAXYEAR)

Year (Min, Max): (1, 9999)

In [23]:
localtime = time.localtime(time.time())
print "local time is:\n\t", localtime

local time is:
time.struct_time(tm_year=2012, tm_mon=11, tm_mday=23, tm_hour=19, tm_min=3, tm_sec=19, tm_wday=4, tm_yday=328, tm_isdst=0)

In [24]:
print "local time is:\n\t", time.asctime(localtime)

local time is:
Fri Nov 23 19:03:19 2012

In [ ]:
import datetime

In [35]:
# what timezone are you in
print time.tzname

('Eastern Standard Time', 'Eastern Daylight Time')


#### Show me a calendar¶

In [29]:
import calendar
# set Sunday as 1st column
calendar.setfirstweekday(6)
# show calendar for a month
cal = calendar.month(2012,11)
print cal

   November 2012
Su Mo Tu We Th Fr Sa
1  2  3
4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30


In [32]:
# show calendar for a year
cal2 = calendar.calendar(2012)
print cal2

                                  2012

January                   February                   March
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
1  2  3  4  5  6  7                1  2  3  4                   1  2  3
8  9 10 11 12 13 14       5  6  7  8  9 10 11       4  5  6  7  8  9 10
15 16 17 18 19 20 21      12 13 14 15 16 17 18      11 12 13 14 15 16 17
22 23 24 25 26 27 28      19 20 21 22 23 24 25      18 19 20 21 22 23 24
29 30 31                  26 27 28 29               25 26 27 28 29 30 31

April                      May                       June
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
1  2  3  4  5  6  7             1  2  3  4  5                      1  2
8  9 10 11 12 13 14       6  7  8  9 10 11 12       3  4  5  6  7  8  9
15 16 17 18 19 20 21      13 14 15 16 17 18 19      10 11 12 13 14 15 16
22 23 24 25 26 27 28      20 21 22 23 24 25 26      17 18 19 20 21 22 23
29 30                     27 28 29 30 31            24 25 26 27 28 29 30

July                     August                  September
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
1  2  3  4  5  6  7                1  2  3  4                         1
8  9 10 11 12 13 14       5  6  7  8  9 10 11       2  3  4  5  6  7  8
15 16 17 18 19 20 21      12 13 14 15 16 17 18       9 10 11 12 13 14 15
22 23 24 25 26 27 28      19 20 21 22 23 24 25      16 17 18 19 20 21 22
29 30 31                  26 27 28 29 30 31         23 24 25 26 27 28 29
30

October                   November                  December
Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
1  2  3  4  5  6                   1  2  3                         1
7  8  9 10 11 12 13       4  5  6  7  8  9 10       2  3  4  5  6  7  8
14 15 16 17 18 19 20      11 12 13 14 15 16 17       9 10 11 12 13 14 15
21 22 23 24 25 26 27      18 19 20 21 22 23 24      16 17 18 19 20 21 22
28 29 30 31               25 26 27 28 29 30         23 24 25 26 27 28 29
30 31



#### Story of Time by a modern string physicist¶

In [44]:
from IPython.display import YouTubeVideo