-3

i want to use Class and try~except function to make codes. input is that i put integer (ex: 20160101) then it converts to datetime. And final output is the day of the week.

I think i can convert integer to date like this:

>>>import datetime 
>>>d = "20160101" 
>>>d_datetime = datetime.datetime.strptime(d, '%Y%m%d')

but i don't know how to make code example using class,please help me to make codes...

Ellena
  • 1
  • You need to make an attempt first, or else you won't be able to get much help. We can help you fix problems, but not write code for you. – Chris Jun 21 '16 at 02:46

1 Answers1

0

I didn't understand exactly what you are looking for, may be you want something like this

import datetime

class Day:
    def __init__(self, date_str):
        self._date = datetime.datetime.strptime(date_str, '%Y%m%d')

    def dayOfWeek(self):
        return self._date.weekday()


d = Day("20011222")
print (d.dayOfWeek())