如何从python中的给定日期找出星期几?

时间:2016-03-04 11:47:35

标签: python python-3.x

  

编写一个接受包含特定字符串的字符串的函数   格里高利历中的日期。你的功能应该返回哪一天   这一周是。以下是输入内容的几个示例   字符串(月日年)看起来像。但是,你不应该   '硬编码'你的程序只适用于这些输入!

<s:checkbox name="isActive" id="isActive" value="%{user.isActive}"
  

请注意,每个项目(月日年)由一个空格分隔。对于   示例,如果输入字符串是:

"June 12 2012"
"September 3 1955"
"August 4 1843" 
  

然后你的函数应该返回星期几(字符串),例如:

"May 5 1992"
  

带有示例示例的算法:

"Tuesday"
  

自从我们获得2,1992年5月5日是星期二

我的第一个问题是如何接受# Assume that input was "May 5 1992" day (d) = 5 # It is the 5th day month (m) = 3 # (*** Count starts at March i.e March = 1, April = 2, ... January = 11, February = 12) century (c) = 19 # the first two characters of the century year (y) = 92 # Year is 1992 (*** if month is January or february decrease one year) # Formula and calculation day of the week (w) = (d + floor(2.6m - 0.2) - 2c + y + floor(y/4) + floor(c/4)) modulo 7 after calculation we get, (w) = 2 Count for the day of the week starts at Sunday, i.e Sunday = 0, Monday = 1, Tuesday = 2, ... Saturday = 6 作为用户的输入?有什么方法可以让我这样做吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

user_input = input('Enter the date')