Pages

Sunday, April 28, 2013

Python time.asctime exercises


Now I have been playing enough time.asctime to have confidenct to move on to display the time in Guzunty LEDs.


# *** Python time.asctime exercise v5.0 - tlfong01 2013apr28 ***

import time

timeString =  time.asctime(time.localtime(time.time()))
print timeString

print "Hour   digit 1 = ", timeString[11:12]
print "Hour   digit 2 = ", timeString[12:13]
print "Minute digit 1 = ", timeString[14:15]
print "Minute digit 2 = ", timeString[15:16]
print "Second digit 1 = ", timeString[17:18]
print "Second digit 2 = ", timeString[18:19]

hourDoubleDigit = [timeString[11:12], timeString[12:13]]
print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
print "hourDoubleDigit 1 = ", hourDoubleDigit[1]

minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]

secondDoubleDigit = [timeString[17:18], timeString[18:19]]
print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
print "secondDoubleDigit 1 = ", secondDoubleDigit[1]

timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

# *** Sample output ***
# Sun Apr 28 02:57:51 2013
# Hour   digit 1 =  0
# Hour   digit 2 =  2
# Minute digit 1 =  5
# Minute digit 2 =  7
# Second digit 1 =  5
# Second digit 2 =  1
# hourDoubleDigit 0 =  0
# hourDoubleDigit 1 =  2
# minuteDoubleDigit 0 =  5
# minuteDoubleDigit 1 =  7
# secondDoubleDigit 0 =  5
# secondDoubleDigit 1 =  1
# hour =  0 2
# minute =  5 7
# second =  5 1

# .END

No comments:

Post a Comment